GeeCON Prague 2014*
The moose likes JDBC and the fly likes Problem in updating a table . Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in updating a table ." Watch "Problem in updating a table ." New topic
Author

Problem in updating a table .

Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Hi Ranchers,


We have a problem in updating a table in MySQL.

the query used is
String sqlUpdateStatus = "UPDATE candidate_login_tbl SET "+
" candidate_login_status ='l', "+
" candidate_last_login_date ='"+ dt +
"' where candidate_id = "+ candidateID +";";

System.out.println(sqlUpdateStatus);
stmt3 = conn.createStatement();
stmt3.executeUpdate(sqlUpdateStatus);

when run It doesn't give any error but at the same time does not update
the table.
Also if i copy the print out put and run it directly in the mySQL query browser the table gets updated.


Can some one help me out.

thanks,
Ganesh
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Hi!

Try removing the date. Is it a datetime in the database. Does
it look ok. Try using

try{

}catch( Exception e ){
e.printStackTrace();
}


SCJP1.4
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
You need to explicitly call conn.commit() after the update(s) or set the auto-commit property of the connection to true.

Otherwise the sql will be applied but rolled back once the connection is closed.
Ganesh Chandrasekaran
Greenhorn

Joined: Nov 14, 2000
Posts: 22
Hi

Thanks Mathias Nilsson
Thanks Scott Johnson


When i added conn.commit(), it worked.

Thank you very much.
Ganesh
 
GeeCON Prague 2014
 
subject: Problem in updating a table .