简体   繁体   中英

JDBC exception at getting decimal out parameter of stored procedure

I'm trying to get parameter from MYSQL procedure. My proc:

CREATE PROCEDURE proc(someIn INT UNSIGNED, 
                      anotherIn INT UNSIGNED, 
                      OUT x DECIMAL(10,7),
                      OUT y DECIMAL(10,7))

My java code:

CallableStatement cs = conn.prepareCall("{call proc(?, ?,?,?)}");
cs.setLong(1, someLong);
cs.setLong(2, anotherLong);
cs.registerOutParameter(3,Types.DECIMAL,7);
cs.registerOutParameter(4,Types.DECIMAL,7);
rs = cs.executeQuery();
if (rs.next()) {
    double x = rs.getBigDecimal(3).doubleValue(); 
    double y = rs.getBigDecimal(4).doubleValue();
}

And I encountered on error at calling rs.next():

java.sql.SQLException: ResultSet is from UPDATE. No Data.

If I call the procedure with the same parameters manually, I get the result data. I tried to change decimal to double, but this has no effect.

The correct way to call the procedure is this:

cs.execute();
double x = cs.getBigDecimal(3).doubleValue(); 
double y = cs.getBigDecimal(4).doubleValue();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM