我试图在立即插入记录后检索序列ID。我得到了java.sql.SQLException: Unsupported feature
。我搜索并发现问题ojdbc14.jar
不支持此Statement.RETURN_GENERATED_KEYS
或PreparedStatement.RETURN_GENERATED_KEYS
。所以我用ojdbc6.jar
文件替换。但仍面临同样的问题。有没有针对此问题的解决方法。我也发布了jdbc代码。
conn = DbUtils.getConnection();
String sql = "insert into abcimages (ACCOUNT_ID, LANGUAGE_CODE, CNTR_ID, IG_CAT_ID, CP_ID, MY_GRP_ID," +
"FILE_TYPE_CODE, IG_NAME, IG_DESCR, START_VALID_DATE, END_VALID_DATE, IG_BIN) values (?,?,?,?,?,?,?,?,?,?,?,?)" ;
// PreparedStatement pstmt = conn.prepareStatement(sql, PreparedStatement.RETURN_GENERATED_KEYS);
PreparedStatement pstmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
pstmt.setLong(1, 1234);
pstmt.setString(2, "ENG");
pstmt.setLong(3, new Long(addDetails.getCntr_id()));
pstmt.setLong(4, new Long(addDetails.getImage_cat_id()));
pstmt.setLong(5, new Long(addDetails.getCpn_id()));
pstmt.setString(6, null);
pstmt.setString(7, "JPG");
pstmt.setString(8, addDetails.getImage_name());
pstmt.setString(9, addDetails.getImage_descr());
pstmt.setDate(10, sqlStartDate);
pstmt.setDate(11, sqlendDate);
pstmt.setNull(12, java.sql.Types.BLOB);
pstmt.executeUpdate();
if (pstmt.executeUpdate() > 0) {
java.sql.ResultSet generatedKeys = pstmt.getGeneratedKeys();
if (generatedKeys.next())
key = generatedKeys.getInt(1);
}
// updateImage(imgfile, conn);
pstmt.close();
conn.close();
}catch (DbConnectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "Oops ! Something Went Wrong. Please Check CWC_PROD_LOG_OUT.";
}finally{
DbUtils.closeConnection(conn);
}
return "Successfully Updated !!!";
对此的任何帮助都非常感激。