[英]resultset.getTimestamp and ThreadLocal warning Java
I have started getting lots of warnings whenever I restart my server lately. 每当我最近重新启动服务器时,我已经开始收到很多警告。 The warning looks like this:
警告看起来像这样:
the web application [/xxx] created a ThreadLocal with key of type [net.sourceforge.jtds.jdbc.Support$1] (value [net.sourceforge.jtds.jdbc.Support$1@29173d71]) and a value of type [java.util.GregorianCalendar] ... but failed to remove it when the web application was stopped. Web应用程序[/ xxx]创建了一个ThreadLocal,其密钥类型为[net.sourceforge.jtds.jdbc.Support $ 1](值[net.sourceforge.jtds.jdbc.Support$1@29173d71]),类型为[java] .util.GregorianCalendar] ...,但是在Web应用程序停止时无法将其删除。
I finally found the line in the code that creates it: 我终于在创建它的代码中找到该行:
cp.setCreationDate(rset.getTimestamp("CreationDate")); cp.setCreationDate(rset.getTimestamp(“ CreationDate”));;
rset is of type java.sql.ResultSet rset的类型为java.sql.ResultSet
Is there something wrong with how I get the date from database or is there a way to remove the calendar? 我如何从数据库中获取日期是否有问题,或者是否可以删除日历? We have always done it like this and I don't know why these errors has started, but they really spam the logs now.
我们一直都是这样做的,我不知道为什么会开始出现这些错误,但现在它们确实在垃圾邮件中。
I found this thread: Java ResultSet.getTimestamp using Calendar & Thread safety 我找到了这个线程: 使用Calendar&Thread安全的Java ResultSet.getTimestamp
but I still get the errors. 但我仍然得到错误。
完成ResultSet对象本身后,调用rset.close()
,这将释放ResultSet保留的资源。
I closed the resultset. 我关闭了结果集。 This is the code now (simplified to just show my problem):
这是现在的代码(简化为仅显示我的问题):
public CompanyPerson getCompanyPerson(int personId) throws SQLException {
CompanyPerson person = new CompanyPerson();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
StringBuffer sql = new StringBuffer();
sql.append(" select CreationDate from CMCompanyPeople person ");
sql.append(" where person.PersonId=?");
try {
con = dataSource.getConnection();
pstmt = con.prepareStatement(sql.toString());
pstmt.setInt(1,personId);
rset = pstmt.executeQuery();
if (rset.next()) {
Timestamp t = rset.getTimestamp("CreationDate");
}
rset.close();
pstmt.close();
con.close();
} catch (SQLException e) {
throw e;
} finally {
closeConnection(con);
}
return person;
}
When i run the code the server restarted and I got the above error. 当我运行代码时,服务器重新启动,并且出现上述错误。
After removing the following code i did not get any error 删除以下代码后,我没有收到任何错误
Timestamp t = rset.getTimestamp("CreationDate"); 时间戳记t = rset.getTimestamp(“ CreationDate”);
What is going on here? 这里发生了什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.