Java 不支持的功能异常fetchDmlReturnParams
我有这个密码Java 不支持的功能异常fetchDmlReturnParams,java,ojdbc,Java,Ojdbc,我有这个密码 String sql = "insert into colortable (string, color, cid) values (?,?,?)"; PreparedStatement ps = conn.prepareStatement(sql,keyProperties.toArray(new String[0])); ps.executeBatch(); final ResultSet rst = ps.getGeneratedKeys(); while (rst.next
String sql = "insert into colortable (string, color, cid) values (?,?,?)";
PreparedStatement ps = conn.prepareStatement(sql,keyProperties.toArray(new String[0]));
ps.executeBatch();
final ResultSet rst = ps.getGeneratedKeys();
while (rst.next()) {
final BigDecimal bigDecimal = rst.getBigDecimal(1);
if (bigDecimal != null) {
ids.add(bigDecimal.intValueExact());
}
}
当代码到达rst.next时,我得到以下异常
Caused by: java.sql.SQLException: Unsupported feature
at oracle.jdbc.driver.OracleStatement.fetchDmlReturnParams(OracleStatement.java:4959) ~[ojdbc6.jar:11.2.0.4.0]
at oracle.jdbc.driver.OracleReturnResultSet.next(OracleReturnResultSet.java:63) ~[ojdbc6.jar:11.2.0.4.0]
我发现问题出在ojdbc驱动程序的这一部分
if (!this.statement.returnParamsFetched) {
this.statement.fetchDmlReturnParams();
this.statement.setupReturnParamAccessors();
}
特别是函数this.statement.fetchDmlReturnParams();没有实施
现在我的问题是,如何避免调用此函数,特别是returnParamFetched是否可以设置为true?我的应用程序真正执行的代码是
try {
final String sql = "insert into colortable (string, color, cid) values (?,?,?)";
final PreparedStatement ps = conn.prepareStatement(sql, new String[] {"ID"});
ps.setString(1, "TEST1");
ps.setString(2, "FFFFFF");
ps.setInt(3, 1);
ps.addBatch();
ps.setString(1, "TEST2");
ps.setString(2, "AAAAAA");
ps.setInt(3, 1);
ps.addBatch();
ps.executeBatch();
final ResultSet rst = ps.getGeneratedKeys();
rst.getMetaData();
if (rst != null){
while (rst.next()) {
final BigDecimal bigDecimal = rst.getBigDecimal(1);
System.out.println(bigDecimal);
Assert.notNull(bigDecimal);
}
}
ps.close();
}catch (final SQLException e){
System.out.println(e);
}finally {
}
我创建了一个测试用例来测试这段代码,我尝试了不同的ojdbc,我发现最新的ojdb8解决了这个问题