Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am trying to insert some data using preparedStatement
stringbuffer.append("Insert into testuser(username,email,testname,testdate,");
stringbuffer.append("validityperiod,testid,percentage,message)");
stringbuffer.append("values(?,?,?,'"+s4+"','"+s4+"',?,?,?)");

PreparedStatement preparedstatement = connection.prepareStatement(stringbuffer.toString());

preparedstatement.setString(1, s1);
preparedstatement.setString(2, s2);
preparedstatement.setString(3, s3);
//preparedstatement.setString(4, s4);
//preparedstatement.setString(5, s4);
//preparedstatement.setString(6, s6);
preparedstatement.setInt(6, Integer.parseInt(s6));
//preparedstatement.setString(7, s7);
preparedstatement.setInt(7, Integer.parseInt(s7));
preparedstatement.setString(8, s8);

System.out.println("After insertion");

statement.executeUpdate(stringbuffer.toString());


here s4 is sate like( 05-january-2005)




this is the error appeared at consloe window of tomcat
java.sql.SQLException: ORA-01008: not all variables bound

what might be the problem

please help me...

cinux
 
sinasi susam
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


with this line you have to bind 6 variables.It asks you bind all variables,with indexes 1 to 6.
[ December 05, 2005: Message edited by: sinasi susam ]
 
sinasi susam
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And also you will need to u,execute the method with ;

statement.executeUpdate();

you dont put sql string into method again ,...
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok now i have modified my code to this



stringbuffer.append("Insert into testuser(username,email,testname,testdate,");
stringbuffer.append("validityperiod,testid,percentage,message)");
stringbuffer.append("values(?,?,?,?,?,?,?,?)");

PreparedStatement preparedstatement = connection.prepareStatement(stringbuffer.toString());

preparedstatement.setString(1, s1);
preparedstatement.setString(2, s2);
preparedstatement.setString(3, s3);
preparedstatement.setString(4, s4);
preparedstatement.setString(5, s4);

//preparedstatement.setString(6, s6);
preparedstatement.setInt(6, Integer.parseInt(s6));

//preparedstatement.setString(7, s7);
preparedstatement.setInt(7, Integer.parseInt(s7));
preparedstatement.setString(8, s8);

System.out.println("After insertion");

statement.executeUpdate(stringbuffer.toString());


now also i am getting the saem error


what to do?
 
sinasi susam
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
statement.executeUpdate();
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34681
367
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saikrishna,

should be

With a prepared statement, you set the SQL string at the beginning when you create the statement. With a regular statement, you pass the SQL when you call an execute method. Since you are passing the SQL when you call executeUpdate(), Java thinks you have a regular statement and doesn't know what to do with the question marks.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have also tested it by using

preparedstatement.executeUpdate();

but no advantage

is there any other way to insert my values into table???



cinux
 
sinasi susam
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dont give up immediately.

that should work;



do it as it is, it will work.If still not working probably your doing something wrong again.That must work.if your driver supports preparedstatement that it seems it does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic