I have a web development project using local install of Tomcat 7
. I am trying to connect to SQL Server 2012
using Microsoft's driver for jdbc (sqljdbc41.jar
).
The sqljdbc41.jar
is in my application build path:
and I am exporting it. Furthermore, in the Tomcat application directory lib
folder I have also placed a copy of sqljdbc41.jar
.
There are no compile errors, but at runtime when I try to load the SQL Server driver I get the following:
ClassNotFoundException - com.microsoft.jdbc.sqlserver.SQLServerDriver
The exception is thrown in the following code block:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://"+server+":1433;databaseName="+database+";user=sa;password="+password+";";
con = (Connection) DriverManager.getConnection(connectionUrl);
I have seen many posts on this topic without resolution:
- java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver : Am I loading the right driver?
- https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b425c201-9882-4a48-b049-4004f202b0c6/javalangclassnotfoundexception-commicrosoftsqlserverjdbcsqlserverdriver?forum=sqldataaccess
- Getting ClassNotFoundException on code: "Class.forName("com.microsoft.sqlserver.jdbc.SqlServerDriver");"
and many more.
Compiler level 1.7 and a JRE of 1.7 - According to documentation, I believe I am using the correct driver. This also states that the CLASSPATH must be set:
echo $CLASSPATH
/var/common/sqljdbc41.jar
Which it is. Furthermore:
java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM)
64-Bit Server VM (build 24.75-b04, mixed mode)
So, why am I still encountering this???
Update
I downloaded the sqljdbc41.jar
from Microsoft again - just to be sure that somehow the first jar was not corrupt.
Following Mick Mnemonic's link, I removed the jar from the Java Build path and put the newly downloaded jar into the WEB-INF/lib
folder of the web application. I then restarted Eclipse and the Tomcat server and cleaned the Tomcat server, and the project.
Still getting the ClassNotFoundException
.
sqljdbc41.jar
. I am not sure that's an option yet. I will check into it. Thanks, I really do appreciate the help! – Roy HinkleyCLASSPATH
variable when it starts up. You probably just need to add the library tocatalina.properties
as instructed in this blog post. – Mick Mnemonic