Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!