This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
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


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
sinasi susam
Ranch Hand

Joined: Jul 15, 2005
Posts: 67


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

Joined: Jul 15, 2005
Posts: 67
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

Joined: Apr 16, 2005
Posts: 689
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

Joined: Jul 15, 2005
Posts: 67
statement.executeUpdate();
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30057
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
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

Joined: Jul 15, 2005
Posts: 67
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: ORA-01008: not all variables bound
 
Similar Threads
SQLException: ORA-01008
Integration test on JDBC (No Hibernate !) and Spring AbstractTransactionalJUnit4SpringContextTests
java.sql.SQLException: ORA-01008: not all variables bound
SQLException: ORA-01008
ORA-01008: not all variables bound