• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java and jdbc

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd probably get better response in the JDBC forum. I'm moving this there.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic