• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLException -- help needed

 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know I should not be asking this question in this forum but since it is urgent I am asking..
I am using Oracle db & JDBC. When I prepare a query using prepare statement & then call setInt methods to set the place holders & then execute the query I am getting a SQLException that says all variables not bound..
Can somebody tell what I need to do to fix this exception..
Thanks,
Roopa.
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The number of '?' in your prepared statement should match the number of setXXX() method calls you make. It sounds like you have not set values for all the place holders.
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shilpa I have 2 ? & therefore 2 setInt statements after that..
Originally posted by Roopa Bagur:
I know I should not be asking this question in this forum but since it is urgent I am asking..
I am using Oracle db & JDBC. When I prepare a query using prepare statement & then call setInt methods to set the place holders & then execute the query I am getting a SQLException that says all variables not bound..
Can somebody tell what I need to do to fix this exception..
Thanks,
Roopa.

 
Marilyn de Queiroz
Sheriff
Posts: 9068
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the JDBC forum since it is not covered by the SCJP exam.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than trying to guess what you're doing, can tyou drop the relevant code here so we can see what you are doing?
ta,
Dave.
 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code:

public void modifyQuestion( String creatorId, String categoryId,
QuizQuestion question ) throws SQLException
{
String query = new String("Select Q.Question_Text From
AllQuestions_VW Q WHERE Q.Question# = ? AND Q.Category# = ? AND TRU_DT IS
NULL For Update ");
System.out.println( "query: " + query );
PreparedStatement prepStatement = null;
ResultSet rs = null;
try
{
_conn.setAutoCommit( false );
prepStatement = _conn.prepareStatement( query );
prepStatement.setInt( 1,
Integer.valueOf( question.getQuestionId() ).intValue() );
prepStatement.setInt( 2, Integer.valueOf( categoryId ).intValue() );
prepStatement.execute(query); // exception on this
statement

Exception message text: ORA-01008: not all variables bound
Originally posted by David O'Meara:
Rather than trying to guess what you're doing, can tyou drop the relevant code here so we can see what you are doing?
ta,
Dave.

 
Roopa Bagur
Ranch Hand
Posts: 267
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the problem...
The problem was I was doing a prepStat.execute(query)....
The theory is prep statement inherits from Statement class but has it own implementation of executeQuery & executeUpdate i.e both these methods do not accept any parameters unlike the Statement class which does...
Bingo!!! I changed the code to call prepStat.executeQuery() &
every thing worked..
Thanks
Originally posted by David O'Meara:
Rather than trying to guess what you're doing, can tyou drop the relevant code here so we can see what you are doing?
ta,
Dave.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic