wood burning stoves 2.0*
The moose likes JDBC and the fly likes java and jdbc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java and jdbc" Watch "java and jdbc" New topic
Author

java and jdbc

Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
I am trying to execute a stored procedure in a database using the prepareCall method. This is how I use it to call a procedure passing two paramters.
connect.prepareCall("call procedure[(?,?)]}");
How do I change this if my procedure does not pass in any parameters but returns two parameters. I want to also go through a loop and assign what is returned to variables. THe first thing returned is a string, and the second argument returned is a float. Thank you.
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You'd probably get better response in the JDBC forum. I'm moving this there.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

no change. The only change is to declare the out parameters of the stored procedure ( different than return vals, but since you can only return one value, I assume you meant out parameters )
Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
thank you
Chanpreet Julka
Ranch Hand

Joined: Nov 09, 2001
Posts: 40
Here is the error I am getting
java.sql.SQLException: JZ0SA: Prepared Statement: Input parameter not set, ind
ex: 2.
And here is the code..
CallableStatement cstmt = con.prepareCall("{ ? = call RET_ANT_NAME_UP_BY_MAX_VERSION[(?,?)]}");
cstmt.registerOutParameter ( 1, java.sql.Types.VARCHAR );
cstmt.registerOutParameter ( 2, java.sql.Types.FLOAT );
cstmt.execute();
String outParam1 = cstmt.getString( 1 );
float outParam2 = cstmt.getFloat( 2 );
I want to return two arguments from the stored procedure, and do not want to pass any inputs in to the procedure as parameters. Help please? Thanks
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

your error is that you have 3 ?'s in your prepareCall method, but you only define( register ) 2 of them. you probably want this:

this should work ( only 2 parameters ).
Jamie
 
jQuery in Action, 2nd edition
 
subject: java and jdbc