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