Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 不定期的null pointer exception
king_wjb





发贴: 27
积分: 0
于 2007-01-26 15:53 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我用的是oracle数据库,通过连接池连接,在运行的过程中经常出现null pointer exception,而且不一定是在哪个类以及哪个方法中,例如如下代码:

public static int executeSqlReturnCount(String sql) throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("sql:" + sql);
    }
    Statement stmt;
    Connection conn;
    // 获取数据库连接
    conn = ConnectDB.getDBConnection();
    // 创建Statement对象
    stmt = conn.createStatement(); //这一行经常会出现null pointer exception
    // 执行SQL语句并将查询结果放入结果集中
    ResultSet rs = stmt.executeQuery(sql);
    // 将结果集中的数据取出放入User类的对象中
    if (log.isDebugEnabled()) {
      log.debug("sql over");
    }
    int result = 0;
    if (rs.next()) {
      result = rs.getInt(1);
    }
    DBUtil.closeResultSet(rs);
    DBUtil.closeStatement(stmt);
    ConnectDB.freeDBConnection(conn);
    return result;
  }

我怀疑是连接未正常释放,但是查了所有的类中的方法,都有ConnectDB.freeDBConnection(conn);
我找不出原因,请各位帮忙看看,谢谢!



作者 Re:不定期的null pointer exception [Re:king_wjb]
九佰



版主


发贴: 983
积分: 126
于 2007-01-26 20:19 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
stmt = conn.createStatement(); //这一行经常会出现null pointer exception

看情况好象是conn=ConnectDB.getDBConnection();有问题
看看ConnectDB.getDBConnection()能否有产生null的情况,
在程序里面判断一下
conn=ConnectDB.getDBConnection();
if(conn == null){
...
}else{
...
}




http://www.teamlet.org

海纳百川,有容乃大
壁立千仞,无欲则刚
智者不惑,勇者无惧
止戈为武,仁者无敌
作者 Re:不定期的null pointer exception [Re:九佰]
king_wjb





发贴: 27
积分: 0
于 2007-01-29 12:01 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
这个异常不是每次都能出现,而且现在很难理解为什么ConnectDB.getDBConnection()会返回空的连接。



flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923