Arturas M
Arturas M

Reputation: 4369

Tomcat not loading libs

well my Tomcat (run via Eclipse) seems to fail to load the SQL Server driver lib:

 java.lang.NullPointerException
java.lang.RuntimeException
    at org.ktu.gdia.core.MainController.processFile(MainController.java:132)
    at org.ktu.gdia.core.MainController.run(MainController.java:57)
java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://isd.ktu.lt:1433;DatabaseName=LN2012_bakDB2
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.apache.tomcat.dbcp.dbcp.DriverManagerConnectionFactory.createConnection(DriverManagerConnectionFactory.java:75)
    at org.apache.tomcat.dbcp.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1185)
    at org.apache.tomcat.dbcp.dbcp.PoolingDriver.connect(PoolingDriver.java:180)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at org.ktu.gdia.database.DbActions.openConn(DbActions.java:64)
    at org.ktu.gdia.core.MainController.processFile(MainController.java:134)
    at org.ktu.gdia.core.MainController.run(MainController.java:57)
Exception in thread "Thread-2" java.lang.NullPointerException
    at org.ktu.gdia.database.GenForestDatabase.personExists(GenForestDatabase.java:178)
    at org.ktu.gdia.core.MainController.processFile(MainController.java:158)
    at org.ktu.gdia.core.MainController.run(MainController.java:57)

the sqljdbc.jar and sqljdb4.jar and jtds-1.3.0.jar are in the Tomcat/lib directory. I'm using Tomcat 7. Is it possible, that Eclipse makes Tomcat use a different lib directory then the one in the Tomcat 7 which it is supposed to use?

Upvotes: 0

Views: 434

Answers (2)

duffymo
duffymo

Reputation: 308988

You don't need all of those JARs, just the one that you actually want to load. It appears to the Microsoft driver, not jTDS.

I don't know what Eclipse is doing, but Tomcat expects JDBC driver JARs to be loaded from its /lib directory.

I don't agree that the problem is failing to load the driver. "No suitable driver" usually means that the URL syntax in the connection string is incorrect.

You have

jdbc:microsoft:sqlserver://isd.ktu.lt:1433;DatabaseName=LN2012_bakDB2

This URL suggests the following format:

jdbc:sqlserver://host:1433;databaseName=dbNameHere;integratedSecurity=true;

If the URL appears to be right, I'd start checking other things:

  1. Can you ping server isd.ktu.lt from the server where you run your Java app? If you can't see that server Java won't, either.
  2. Can you successfully connect to that server using Microsoft SQL Server Studio? If it can't Java won't, either.
  3. Are you certain that the SQL Server listener is configured to listen on port 1433, the default? Lots of DBAs choose something other than the default for security reasons.
  4. Looks like you're using a database connection pool, as you should. Check to see that your JNDI configuration is correct.

Here's configuration from an app that successfully connects to SQL Server:

    <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
    <property name="url" value="jdbc:sqlserver://host:port;databaseName=db"/>

Upvotes: 1

1218985
1218985

Reputation: 8032

Your URL must be jdbc:sqlserver://server:port;DatabaseName=yourDbName and Class name must be like com.microsoft.sqlserver.jdbc.SQLServerDriver. You can download and use the MicrosoftSQL Server JDBC Driver 2.0 from here

Upvotes: 0

Related Questions