Author
Problrm with update statement syntax
vanan saravanan
Ranch Hand
Joined: Jun 02, 2006
Posts: 95
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
Joined: Dec 15, 2005
Posts: 333
posted Jul 03, 2006 21:06:00
0
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
Joined: Jun 02, 2006
Posts: 95
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
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.
[Blog ] [JavaRanch FAQ ] [How To Ask Questions The Smart Way ] [Book Promos ]
Blogging on Certs: SCEA Part 1 , Part 2 & 3 , Core Spring 3 , OCAJP , OCPJP beta , TOGAF part 1 and part 2
vanan saravanan
Ranch Hand
Joined: Jun 02, 2006
Posts: 95
Thank you it works now
subject: Problrm with update statement syntax