I need to change package variable using JDBC and get new value back.
When I do it via java.sql.Connection, it returns new value of variable – 345:
BigDecimal newValue = BigDecimal.valueOf(345);
try (Connection conn = JDBCDataSource.getConnection()) {
try (CallableStatement stmt = conn.prepareCall("{ call test_pkg.test_num := ? }")) {
stmt.setBigDecimal(1, newValue);
stmt.executeUpdate();
conn.commit();
}
}
BigDecimal retVal;
try (Connection conn = JDBCDataSource.getConnection()) {
try (CallableStatement stmt = conn.prepareCall("{? = call test_pkg.test_num}")) {
stmt.registerOutParameter(1, Types.DECIMAL);
stmt.executeUpdate();
retVal = stmt.getBigDecimal(1);
}
}
System.out.println(retVal);
But if unwrap java.sql.Connection to oracle.jdbc.OracleConnection using conn.unwrap(OracleConnection.class)
then it returns original value, not the new one.
I need to understand why it works in such way with OracleConnection and how to resolve it.