This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes What is wrong with this Update Query!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "What is wrong with this Update Query!!!! " Watch "What is wrong with this Update Query!!!! " New topic
Author

What is wrong with this Update Query!!!!

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Hi Friends,
This my update query and I don't understand why it gives me error!!!
Please help...
Thanks,
Elahe
PrepStmt=con.prepareStatement("update bug set values (?,?,?,?,?) where bugNumber=?");
PrepStmt.setInt(1,ID);
PrepStmt.setString(2,bdesc);
PrepStmt.setString(3,fixedDate);
PrepStmt.setInt(4,userID);
PrepStmt.setString(5,contact);
PrepStmt.setInt(6,bugNumber);
Error:
--------
You have an error in your SQL syntax near 'values (3,'I can not delete the bug#456','2001-01-01',3,'Rick-408-778-2967') whe' at line 1


Thanks,
Elahe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Which database are you using? Not all databases support the syntax that you are using. For example, the UPDATE syntax for PostgreSQL is:
UPDATE [ ONLY ] table SET col = expression [, ...]
[ FROM fromlist ]
[ WHERE condition ]

I believe your statement would work with MySQL.
hth,
bear
[ January 23, 2002: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Yes I'm usubg MySql but why it gives me syntax error
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Yes,I'm using MySql, but why it gives me error
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
I got my answer the query should be like this:
PrepStmt =con.prepareStatement("update bug set ID=?,bdesc=?,fixedDate=?,userID=?,contact=? where bugNumber=?");
Elahe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is wrong with this Update Query!!!!
 
Similar Threads
How to use two query in one servlet
Please help....confused:
Am I correct in where clause...
PreparedStatement not throwing error when it should
How can I solve IllegalArgumentException