Getting TDS driver - java.lang.NullPointerExceptio

2019-06-14 14:47发布

问题:

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"/>