获取TDS驱动程序 - java.lang.NullPointerException。这个异常不一致 [英] Getting TDS driver - java.lang.NullPointerException. this exception is not consistent

查看:414
本文介绍了获取TDS驱动程序 - java.lang.NullPointerException。这个异常不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从3或4个线程调用方法时,我得到异常。这个方法得到一个DataBase连接里面的方法和填充一些值从DB,然后连接(连接,结果集和prepareStatement)正确关闭方法内。仍遇到异常。

I am getting exception when a method is called from 3 or 4 threads. This method get a DataBase connection inside method and populate some values from DB and then connection (connection, resultset and prepareStatement) getting closed properly inside method only. Still getting exception.

Thread_1 - 调用abc()方法。连接在方法中打开和关闭。

Thread_2 - abc()方法调用。连接在方法中打开和关闭。

Thread_3 - abc()方法调用。

Thread_1 - abc() method called. connection opened and closed inside method.
Thread_2 - abc() method called. connection opened and closed inside method.
Thread_3 - abc() method called. connection opened and closed inside method.

我不清楚为什么即使连接正常打开和关闭也会发生异常。
DataBase - Ms sql,
Java - 1.6,apache-tomcat 6。

I am not clear why the exception occurs even though connection opened and closed properly. DataBase - Ms sql, Java - 1.6, apache-tomcat 6.

主要的是它不一致,有时例外发生,有时不发生。

The main thing is that it's not consistent, sometimes exception occurs and sometimes not.

1. Exception -
com.inet.tds.am: 
[TDS Driver]java.lang.NullPointerException                                                                                                                                                
        at com.inet.tds.aj.a(Unknown Source)                                                                                                                                                               
        at com.inet.tds.r.g(Unknown Source)                                                                                                                                                                
        at com.inet.tds.r.executeQuery(Unknown Source)                                                                                                                                                     
        at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93)


2. Exception -
java.sql.SQLException: Connection is closed.                                                                                                                                                               
        at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.checkOpen(PoolingDataSource.java:175)                                                                                  
        at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:301)

请指教。

推荐答案

数据库连接可能不是线程安全的。尽管从您的堆栈跟踪中看到您尝试使用连接池(dbcp),您可能没有正确设置它。如果你更多的问题,更多的配置和你进行数据库调用的代码,也许有人可以发现问题。

The database connection probably isn't thread-safe. Although it appears from your stack trace that you're attempting to use a connection pool (dbcp) you might not have it set up properly. If you update the question with more of your config and the code where you make the DB call, maybe someone can spot the problem.

这篇关于获取TDS驱动程序 - java.lang.NullPointerException。这个异常不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆