Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes SQLException:  bind variable does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQLException:  bind variable does not exist" Watch "SQLException:  bind variable does not exist" New topic
Author

SQLException: bind variable does not exist

Karthika Kannan
Greenhorn

Joined: Feb 18, 2006
Posts: 19
I'm trying to insert a row into a table(Oracle) from a java program, using a sequence(seq.nextval) as the primary key.I'm using a prepared statement for this query:
INSERT INTO TEST VALUES(ERROR_SEQ.nextval,?,?)

I'm getting the following exception:

ORA-01006: bind variable does not exist

Stack Tracejava.sql.SQLException: ORA-01006: bind variable does not exist

Could somebody help me out.
Thanks.

Karthika
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sounds like you are trying to mind a variable that does not exist in your statement. Check your code - are you tring to bind more than two variables?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Karthika,

Could you post your code so that we can find exact problem.Untill then we can guess only.

A common mistake by developers is that whenever they use sequences etc they increment the sqequence number of place holder, possibily same error is here are u doing similar like code below

pstmt(2,Your_First_place_holder);
pstmt(3,Your_Second_place_holder);


Shailesh


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Ann Klein
Greenhorn

Joined: Sep 21, 2003
Posts: 12
SQLquery =
" DECLARE x report_help.seqid%TYPE; " +
" BEGIN " +
" INSERT INTO report_help " +
" ( helptext, creationdate, modifydate ) " +
" VALUES ( ? ,SYSDATE, SYSDATE) " +
" RETURNING x " +
" INTO x; " +
" RETURN; " +
" END;";

int x = 0;
CallableStatement cstmt = null;
try
{
WebLogger.println("SQLquery: " + SQLquery );
cstmt = dbConn.prepareCall(SQLquery);
cstmt.setString(1, v_helptext );
cstmt.registerOutParameter(2, java.sql.Types.TINYINT);
cstmt.executeQuery();
WebLogger.println("x: " + x );
if (rs.next()) {
x = rs.getInt(2);
WebLogger.println("from rs x: " + x );
}
cstmt.close();

getting error on cstmt.executeQuery();
Message: ORA-01006: bind variable does not exist
SQLState: 72000
ErrorCode: 1006
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SQLException: bind variable does not exist
 
Similar Threads
Problem with PreparedStatements...
Reusing PreparedStatement as Statement
java.sql.SQLException: ORA-00942
bind variable does not exist
calling stored proc. w/ resultset return?