lundi 28 mars 2016

Sqlite Formating the Column values before updating

I have table which has column called "TIMESTAMP", "DUR" & "CID". When a row is created "CID" is entered with particular value, "DUR" is enter with "n" . When my application get the same "CID" value second time around I update "DUR" with Time elapsed in Seconds. It is all working fine but I would like to format the output then update "DUR" column in case the result is more the 60secs to ...Min....Sec and if it is more than 3600secs to ....Hrs....Min....secs. How can I do that here is my code;

 public void  adddur(String f, String cid)     
{
  Connection c;
  Statement  stmt;
//  String sq =null;
  try {
  Class.forName("org.sqlite.JDBC");
  c = DriverManager.getConnection("jdbc:sqlite:" + f);
  c.setAutoCommit(false);
  stmt = c.createStatement();
  String  sq = " UPDATE Daily_Calls SET DUR = strftime('%s','now','localtime') - strftime('%s',TIMESTAMP) Where CID="+ "\"" + cid +  "\"" + "AND DUR='n' "+ ";";

  int ucount = stmt.executeUpdate(sq);

  if(ucount < 1) {System.out.println("No Record"); 

  stmt.close();
  c.commit();
  c.close();

   } catch ( ClassNotFoundException | SQLException e ) {
    System.err.println( e.getClass().getName() + ": " + e.getMessage() );
   //er.elog("care.db", "addip", "none", e.getClass().getName() + ": "        +      e.getMessage());  
}


 }  //adddu

Aucun commentaire:

Enregistrer un commentaire