java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
Asked Answered
D

6

7
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

I got the above exception when i trying to deploying my Application into tomcat. but the weird thing is , i tried with a simple main method and it's works fine. Any help please ???

I did the following:

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String connectionUrl = "jdbc:microsoft:sqlserver://localhost:1433;" + "database=DBName;" + "user=UserName;" + "password=Password";
connection = DriverManager.getConnection(connectionUrl);
Dropping answered 14/3, 2013 at 20:26 Comment(2)
I think that the JDBC driver is not in the classpath. What are you using to build your project?Sankhya
Look at one of the other hundred questions about this on this site. I just commented on another one just a minute ago.Titanomachy
U
10

You need to add the jar file containing the class com.microsoft.sqlserver.jdbc.SQLServerDriver to your war file's WEB-INF/lib folder.

Unreel answered 14/3, 2013 at 20:29 Comment(0)
S
3

Read Tomcat Documentation about classpath for clarification or just put the sqljdbc.jar in $CATALINA_HOME/lib to access it from all your applications.

Sankhya answered 14/3, 2013 at 20:33 Comment(0)
P
2

Eventhough you have JAR(sqlserverjdbc.jar) in build path You need to add the jar file containing the class. com.microsoft.sqlserver.jdbc.SQLServerDriver to your war file's WEB-INF/lib folder.

Peyote answered 7/1, 2014 at 12:36 Comment(0)
J
2

May 15, 2014 3:09:43 PM org.apache.tomcat.jdbc.pool.ConnectionPool init SEVERE: Unable to create initial connections of pool. java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254) at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182) at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701) at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635) ...

It is quite puzzling because my web application has WEB-INF/lib/sqljdbc4.jar.

From the error message, somehow the jar file is required by Tomcat too.

After I copy the jar file to CATALINA_HOME/lib/sqljdbc4.jar, the error is gone.

Jumpoff answered 15/5, 2014 at 9:17 Comment(0)
P
0

Since you're running a web app, you need to have the MS SQL Server driver--or the driver for any DB--stored in two places. Inside the app that becomes your WAR and then you need a second copy that is stored in the App Server's LIB directory. So, if you're running on Tomcat then you would put it /opt/tomcat/lib or C:\DEV\tomcat7\lib.

Propagable answered 4/3, 2015 at 20:1 Comment(0)
M
0

I just had the same error running one of my java App from eclipse after uninstalled and re-installed tomcat. I had to create a new Apache Tomcat Runtime from my Project.

From Eclipse Properties > Project Facets > Runtimes as per the following screenshot:

Note: Also, make sure you have a copy of the jdbc jar file into your tomcat library. For example into: C:\Program Files\Apache Software Foundation\Tomcat 9.0\lib\mssql-jdbc-8.4.0.jre11.jar

Project Facet New Runtime

Enjoy!

Merna answered 12/10, 2023 at 19:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.