Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in updating a table .

 
Ganesh Chandrasekaran
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
 
Mathias Nilsson
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();
}
 
Scott Johnson
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic