Getting TDS driver - java.lang.NullPointerException. this exception is not consistent

核能气质少年 提交于 2020-01-03 06:46:14

问题


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() 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.

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)

Please advise on this.


回答1:


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.




回答2:


Please find the config / context file -

 <Resource name="jdbc/mysqlDS" auth="Container" type="javax.sql.DataSource"
            driverClassName="com.inet.tds.TdsDriver"
            url="jdbc:inetdae7://194.0.0.1:1433/july"
            username="team" password="!team!"
            maxActive="50" maxIdle="2" maxWait="10000"
            removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"/>


来源:https://stackoverflow.com/questions/9411706/getting-tds-driver-java-lang-nullpointerexception-this-exception-is-not-consi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!