aspose file tools*
The moose likes JDBC and the fly likes preparedStatement error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "preparedStatement error" Watch "preparedStatement error" New topic
Author

preparedStatement error

sanjay chawla
Greenhorn

Joined: Aug 30, 2001
Posts: 2
Hi,
I am getting this error while using prepare statement.
[BOSTRN01002]Line 1: Incorrect syntax near '?'
My query snippet is:
sql = "INSERT INTO VIGNKR(catid,category,keyword) values(?, ?, ?)";
ps = con.prepareStatement(sql);
ps.setInt(1,8);
ps.setString(2,"Sanjay");
ps.setString(3,"Chawla");
ps.executeUpdate(sql);
Any clues what could have gone wrong!
Regards,
Sanjay
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Try cutting and pasting the SQL into a client and running it (swapping out the ? of course).
My guess is you need a space after the 'values' keyword, but I'm no SQL guru...
Dave.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by sanjay chawla:
Hi,
I am getting this error while using prepare statement.
[BOSTRN01002]Line 1: Incorrect syntax near '?'
My query snippet is:
sql = "INSERT INTO VIGNKR(catid,category,keyword) values(?, ?, ?)";
ps = con.prepareStatement(sql);
ps.setInt(1,8);
ps.setString(2,"Sanjay");
ps.setString(3,"Chawla");
ps.executeUpdate(sql);
Any clues what could have gone wrong!
Regards,
Sanjay

ps.executeUpdate(sql);
when you call the above method, you should not pass any parameters to it. Change it to:
ps.executeUpdate();
what is happening(best guess):
PreparedStatement has no 'public int executeUpdate(String sql)' (only a 'public int executeUpdate()') method, but it does inherit one from the Statement Inferface. So what you are actually doing is statement.executeUpdate("INSERT INTO VIGNKR(catid,category,keyword) values(?, ?, ?)") which is not proper sql syntax since ? is not a number and the String/Varchar fields need single quotes around them. Hope this explanation makes sense to you, it does in my head!
Jamie
Jamie
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: preparedStatement error
 
Similar Threads
Prepared Statement problem in my servlet's data manager
Not authenticating the user
add data to database using JSP script
Inserting date into an MS Access DB
java.sql.SQLException: ORA-01830: date format picture ends before converting entire input string