Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problrm with update statement syntax

 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant seem to get the following update statement to work. It works when i use insert. Please do help. Thank you.

String edu =(String) session.getAttribute("education");
String homeadd =(String) session.getAttribute("homeadd");
String homeno =(String) session.getAttribute("homeno");
String bankacc =(String) session.getAttribute("bankacc");
String postalcode =(String) session.getAttribute("postalcode");
String hpno =(String) session.getAttribute("hpno");
String bankname =(String) session.getAttribute("bankname");



String query2 = Update into tb_employee (Address, Postal_Code, Home_no, Handphone_No, Bank_Name, Bank_Acc, Hightest_Edn) values ('"+homeadd+"','"+postalcode+"','"+homeno+"','"+hpno+"','"+bankname+"','"+bankacc+"','"+edu+"');


stm2.executeUpdate(query2);
 
stu derby
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your UPDATE SQL is absolutely totally 100% wrong. It's not even close to right.

Find a basic SQL reference and use it, don't make stuff up and expect other people to fix your code for you.

http://www.google.com/search?q=sql+syntax+update
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following error when i try ths.
C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\_\fch1\savedetailsupdate$jsp.java:157: ')' expected.
String query2 = (UPDATE tb_employee SET Highest_Edn = '"+edu+"' where emp_ID = '" + userName + "');
^

String edu =(String) session.getAttribute("education");
String homeadd =(String) session.getAttribute("homeadd");
String homeno =(String) session.getAttribute("homeno");
String bankacc =(String) session.getAttribute("bankacc");
String postalcode =(String) session.getAttribute("postalcode");
String hpno =(String) session.getAttribute("hpno");
String bankname =(String) session.getAttribute("bankname");


String query2 = (UPDATE tb_employee SET Highest_Edn = '"+edu+"' where emp_ID = '" + userName + "');
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vanan,
You are missing quotes around the String. Also, query2 is defined twice in the code.

String query2 = (UPDATE ...
should be
String query2 = "(UPDATE ...

If you are just learning, this code is fine. For regular code, it is good practice to keep Java (especially JDBC) out of the JSP. It's much easier to maintain that way.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you it works now
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic