Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JDBC and Relational Databases
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
JDBC and Relational Databases
Update query is wrong?
sahar sa
Ranch Hand
Posts: 102
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
Im having problem with this Update query, I dont know what is wrong? I checked with sun but couldnt find any thing different. still got error!
any idea?
here is the code:
public static void update( String PO, String A, double Value){ PreparedStatement pstmt = null; ResultSet rows ; try{ Connection con = getConnection(); StringBuilder query = new StringBuilder() ; if(A=="Acon"){ query.append("update PO set Acon=?").append(" where PO=?");} else if(A=="Anon"){ query.append("update PO set Anon=?").append(" where PO=?");} String update = query.toString(); pstmt = con.prepareStatement(update); pstmt.setDouble(1,Value); pstmt.setString(2,PO); int result = pstmt.executeUpdate(update); System.out.println("Good has been UPDATED in PO. "); pstmt.close(); con.close(); }catch(Exception ex){ ex.printStackTrace();} }
and error:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? where PO=?' at line 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723) at com.mysql.jdbc.Connection.execSQL(Connection.java:3277) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1402) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1317) at DB.PO.update(PO.java:176) at DB.main.main(main.java:162)
Thank you so much!
Sahar.
Srikkanth Mohanasundaram
Ranch Hand
Posts: 243
1
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
if(A=="Acon"){
I guess this is the problem.
Change this to
if(A.equals("Acon")){
Thanks,
Srikkanth
sahar sa
Ranch Hand
Posts: 102
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I find the answer:
the three methods execute, executeQuery, and executeUpdate are modified so that they take no argument:
source:
http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/preparedstatement.html
thanks,
Sahar.
Satya Maheshwari
Ranch Hand
Posts: 368
posted 15 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If that is the case, did your code even compile?
Thanks and Regards
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
error in update query
COUNT+PSTMT error?
submitting the applet input details to database
taking a particular data from a number of lines
error in Insert Query using Perpared statments
More...