Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

preparedStatement error

 
sanjay chawla
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic