• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in updating a table .  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

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

try{

}catch( Exception e ){
e.printStackTrace();
}
 
Ranch Hand
Posts: 518
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Thanks Mathias Nilsson
Thanks Scott Johnson


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

Thank you very much.
Ganesh
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!