关闭statement时出现NullPointerException

laodaoke laodaoke 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
公司的一个系统出了个很奇怪的问题,方法调用Trace如下:

ABC.java
Java代码
......
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
......
try {
if(A){
theSQL = "******";
connection = theContext.theSQLMgr.getDBSession().getConnection();
ps = connection.prepareStatement(theSQL);
......
}
else{
theSQL = "******";
connection = theContext.theSQLMgr.getDBSession().getConnection();
ps = connection.prepareStatement(theSQL);
......
}
} catch (SQLException e) {
e.printStackTrace();
throw new DBResourceException(e);
} finally {
DBUtils.release(theContext, rs, ps, connection);
}

DBUtils.java
Java代码

public static void release(Context context, ResultSet rs, Statement ps, Connection con) {
if (rs != null) {
context.theSQLMgr.getDBSession().releaseResultSet(rs);
}
if (ps != null) {
context.theSQLMgr.getDBSession().releaseStatement(ps);
}
if (con != null)
context.theSQLMgr.getDBSession().releaseConnection(con);
}

DBSession.class
Java代码

/**
* Releases preparedStatement from the database.
* @param statement
*/
public void releaseStatement(Statement statement) {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
dbSessionLogger.warn("Error:DBSession.releaseStatement", e);
}
}
}

***WrappedStatement.class(implements PreparedStatement)
Java代码

public void close()
throws SQLException
{
SsaGenericApplication.logDebug(this.name + "--[close]:: closing statemt...");
if ((!this.inTrans) || (!this.updateQuery))
{
this.stmt.close();
this.stmt = null;
}
SsaGenericApplication.logDebug(this.name + "--[close]::statment closed");
}

在最后这个class中就报异常了,信息如下:
10:29:10,414 ERROR [STDERR] Caused by: java.lang.NullPointerException
10:29:10,414 ERROR [STDERR] at com.***.service.baseobjects.***WrappedStatement.close(Unknown Source)
10:29:10,414 ERROR [STDERR] at com.agileitp.forte.genericdbms.DBSession.releaseStatement(DBSession.java:202)
10:29:10,414 ERROR [STDERR] at com.***.service.utils.DBUtils.release(DBUtils.java:36)
10:29:10,414 ERROR [STDERR] at com.***.service.dcustomize.TransferP1S1.processStep(TransferP1S1.java:297)
10:29:10,414 ERROR [STDERR] at com.***.service.exeprocessmanager.TransactionService.executeProcedure(Unknown Source)
10:29:10,414 ERROR [STDERR] at com.***.service.exeprocessmanager.TransactionServiceSOBean.executeProcedure(Unknown Source)
10:29:10,414 ERROR [STDERR] at sun.reflect.GeneratedMethodAccessor132.invoke(Unknown Source)
10:29:10,414 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
10:29:10,414 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:592)
10:29:10,414 ERROR [STDERR] at org.jboss.invocation.Invocation.performCall(Invocation.java:359)



理论上,最后一个class的

this.stmt.close();


不可能报错,因为之前已经做过ps!=null的判断了,至此失去思路。

不知错误可能出在哪里?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
laodaoke
Web 开发 81,108 成员 341,721 内容