[英]java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
I got the above exception when i trying to deploying my Application into tomcat. 当我尝试将我的应用程序部署到tomcat时,出现了上述异常。 but the weird thing is , i tried with a simple main method and it's works fine.
但很奇怪的是,我尝试了一种简单的main方法,而且效果很好。 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);
您需要将包含类com.microsoft.sqlserver.jdbc.SQLServerDriver
的jar文件添加到war文件的WEB-INF/lib
文件夹中。
阅读Tomcat文档中有关类路径的说明,或者只是将sqljdbc.jar放在$ CATALINA_HOME / lib中以从所有应用程序访问它。
Eventhough you have JAR(sqlserverjdbc.jar) in build path You need to add the jar file containing the class. 即使构建路径中有JAR(sqlserverjdbc.jar),也需要添加包含该类的jar文件。 com.microsoft.sqlserver.jdbc.SQLServerDriver to your war file's WEB-INF/lib folder.
com.microsoft.sqlserver.jdbc.SQLServerDriver到您的war文件的WEB-INF / lib文件夹中。
May 15, 2014 3:09:43 PM org.apache.tomcat.jdbc.pool.ConnectionPool init SEVERE: Unable to create initial connections of pool.
2014年5月15日,下午3:09:43 org.apache.tomcat.jdbc.pool.ConnectionPool初始化严重:无法创建池的初始连接。 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) ...
java.sql.SQLException:org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)处的com.microsoft.sqlserver.jdbc.SQLServerDriver在org.apache.tomcat.jdbc.pool.PooledConnection.connect处(PooledConnection.java:182)位于org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)位于org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)。 ..
It is quite puzzling because my web application has WEB-INF/lib/sqljdbc4.jar . 这很令人困惑,因为我的Web应用程序具有WEB-INF / lib / sqljdbc4.jar 。
From the error message, somehow the jar file is required by Tomcat too. 从错误消息中,Tomcat也以某种方式需要jar文件。
After I copy the jar file to CATALINA_HOME/lib/sqljdbc4.jar , the error is gone. 将jar文件复制到CATALINA_HOME / lib / sqljdbc4.jar后 ,错误消失了。
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. 由于您正在运行Web应用程序,因此需要将MS SQL Server驱动程序(或任何DB的驱动程序)存储在两个位置。 Inside the app that becomes your WAR and then you need a second copy that is stored in the App Server's LIB directory.
在成为WAR的应用程序内部,然后需要第二个副本,该副本存储在App Server的LIB目录中。 So, if you're running on Tomcat then you would put it /opt/tomcat/lib or C:\\DEV\\tomcat7\\lib.
因此,如果您在Tomcat上运行,则可以将其放在/ opt / tomcat / lib或C:\\ DEV \\ tomcat7 \\ lib。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.