wood burning stoves 2.0*
The moose likes JDBC and the fly likes java.sql.SQLException: ORA-01008: not all variables bound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException: ORA-01008: not all variables bound" Watch "java.sql.SQLException: ORA-01008: not all variables bound" New topic
Author

java.sql.SQLException: ORA-01008: not all variables bound

Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
Hi
I m getting "java.sql.SQLException: ORA-01008: not all variables bound" exception while trying to execute an insert statement. Here is the code snippet

String query = "Insert into Query(Ques_id, Ques, Ans) values(SEQ_QUES_ID.NEXTVAL, ? , ? )";
stat =con.prepareStatement(query);
stat.setString(1,strQues);
stat.setString(2,strAns);
int rowsUpdated = stat.executeUpdate(query);

Here Ques and Ans are of type VARCHAR(150) in DB
I ve checked that there is no problem with the database connection.

thanks in advance


-Priya
SCJP 5.0
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
i am not seeing any problem with this query. may be someone else will point out the problem. or better paste the exact code. in this snippet you are spliting the query string into 2 lines, but not concating the string. i am saying this because sometimes there is only some small space mistake.

usually we get this error when we dont set values for every "?". this might help you. you can try someother value for your primary key instead of using sequence, just to trouble shoot the problem.
Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
There is no problem b'coz of spliting the query
When i used simple Statement instead of prepareStatement, It is executing fine, so no problem with sequence also
Lets see if any body else pin out the error
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

well I dont know if its a typo, but shouldnt we call the executeUpdate() (the no parameter method ) when we execute on a prepared statement? well atleast I did not try to call on executeUpdate and again pass the prepared statement as a parameter ( a method in the Statement which is a super interface of the Prepared Statement). It is also worth while to remember that it is not necessacary that all JDBC drivers provide the functionality that is expected in the sql interfaces, though its a must.

Simple still, is to add the column name that matches to the squence and that would not hinder the performance in any way right?

Regards.
[ December 17, 2004: Message edited by: RajaniKanth Bhargava ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
int rowsUpdated = stat.executeUpdate(query);


yes thanks for pointing it out mate.
didn't you get compile-time error here.
Raj Chila
Ranch Hand

Joined: Mar 18, 2004
Posts: 128

hi,

you would probably not have a compile time error because, Prepared Statement extends the Statement Object.

But could be happening here is, the Values that you set before calling the executeUpdate(stat), might be getting reset because, such a call could be interpreted by the driver as a new Prepared statement.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by RajaniKanth Bhargava:

you would probably not have a compile time error because, Prepared Statement extends the Statement Object.

Bhargava,
thanks again for pointing that out. i couldn't get any thought of it.
Priya Lavti
Ranch Hand

Joined: Oct 11, 2004
Posts: 41
Hi,
Thanks a lot for your reply. My problem has been solved by using stat.executeUpdate();
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: java.sql.SQLException: ORA-01008: not all variables bound