我正在使用JDBC Statement.RETURN_GENERATED_KEYS(https://docs.oracle.com/cd/B19306_01/java.102/b14355/jdbcvers.htm#CHDDJABH)来获取生成的ID和带有序列的插入时间,例如: 插入MY_TABLE(ID,TEXT)值(MY_SEQUENCE.NEXTVAL,'mytext');
然后我正在运行以下代码:
String query = "INSERT INTO MY_TABLE(ID, TEXT) VALUES(MY_SEQUENCE.NEXTVAL, 'mytext')";
try (
PreparedStatement statement = connection.prepareStatement(query, new String[]{"ID"}) {
statement.executeUpdate();
try (
ResultSet result = statement.getGeneratedKeys();
) {
if (result.next()) {
System.out.println(result.getInt(1));
}
}
}
它按预期工作,但是当我停止Tomcat时,出现以下错误:
The web application [SID] created a ThreadLocal with key of type [oracle.jdbc.driver.AutoKeyInfo$1]........but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
在getGeneratedKeys()调用之后,我没有找到任何有关处理资源的文档!
有人可以帮助我吗?
谢谢!