Domanda

I am using java to access mssql 2012 DB

I have a stored procedure "procX" with takes only 1, (say named as @p1) in parameter and returns a single result set. It works fine unless I try to read the return value before I get the result set. Code is below. If I remove "//" and get return value, I get null as the result.

cs = con.prepareCall("{? = call procX(?)}");
cs.registerOutParameter(1, Types.INTEGER);
cs.setInt("p1", 1);
cs.execute();         
//cs.getInt(1);
rs = cs.getResultSet();

And even if I read the return value after I get the resultset, this closes the result set.

Is there a way to read return value without making it impossible to get the resultset?

And as far as I can see this situation is not restricted for return value and occurs for any other output parameters, too.

È stato utile?

Soluzione

Looks like you have to get resultset(s) before reading any of the output parameters.

You can get the detail from https://stackoverflow.com/a/5576442/1519458

Altri suggerimenti

It is interesting,

  • firstly : I do not know what kind of driver are you using but try to change and provide us information will be the same behavior or no.
  • secondly: if you are using Microsoft JDBC Driver for SQL Server try to tune logger and see where is problem, this library using java.util.logging.Logger for logging before/after executing each operations.
  • I think you are using java 7, try to downgrade and run it on Java 6, Why ? Because there is some interesting logic (with Closeable interface) in Microsoft JDBC Driver for SQL Server for getValue method which called from getInt method.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top