• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

preparedStatement error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic