[英]ClassNotFoundException for com.microsoft.sqlserver.jdbc.SQLServerDriver
this is a repeated question, I know. 我知道这是一个重复的问题。
But All those questions are seemingly little unrelated to mine or they're ages old. 但是所有这些问题似乎与我的问题无关,或者它们已经存在很久了。
Steps I've done which I've learnt from previous SO questions and other resources 从以前的SO问题和其他资源中学到的步骤
1.Download sqljdbc driver and add it to class path. 1.下载sqljdbc驱动程序并将其添加到类路径。 I've kept that in
我把它放在
C:\projects\tomcat\webapps\testingfiles\java_files>echo %CLASS_PATH%
C:\projects\tomcat\lib;C:\xampp\tomcat\lib;C:\Program Files\Java;C:\Program Files\Java\jre1.8.0_112;C:\Program Files\Java\jdk1.8.0_112;C:\projects\tomcat\webapps\testingfiles\WEB-INF\lib\sqljdbc4-3.0.jar
Here is my sample code 这是我的示例代码
import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Main { public static void main(String[] args) throws SQLException, ClassNotFoundException { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); Connection conn = DriverManager.getConnection("jdbc:sqlserver://grddwmrtwhqipdw;user=ipdwro;password=readonly;database=IPDW_Prod02"); System.out.println("test"); Statement sta = conn.createStatement(); String Sql = "select * from testing_table"; ResultSet rs = sta.executeQuery(Sql); while (rs.next()) { System.out.println(rs.getString("txt_title")); } } }
C:\\projects\\tomcat\\webapps\\testingfiles\\java_files>java Main Exception in thread "main" java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
C:\\ projects \\ tomcat \\ webapps \\ testingfiles \\ java_files> java线程“主”中的主要异常java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader.findClass(Unknown Source)
在java.net.URLClassLoader.findClass(未知来源)
at java.lang.ClassLoader.loadClass(Unknown Source)
在java.lang.ClassLoader.loadClass(未知来源)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
在sun.misc.Launcher $ AppClassLoader.loadClass(未知来源)
at java.lang.ClassLoader.loadClass(Unknown Source)
在java.lang.ClassLoader.loadClass(未知来源)
at java.lang.Class.forName0(Native Method)
在java.lang.Class.forName0(本地方法)
at java.lang.Class.forName(Unknown Source)
在java.lang.Class.forName(未知来源)
at Main.main(Main.java:10)
在Main.main(Main.java:10)
PS please do not downvote this question because it is repeated, I've searched most of the SO questions and none of them actually were helpful for my cause, thanks! PS,请不要拒绝这个问题,因为它是重复的,我已经搜索了大多数SO问题,但实际上没有一个问题对我的事业有所帮助,谢谢!
Did you placed 'sqljdbc4-3.0.jar' in your project's lib folder and deployed it? 您是否将“ sqljdbc4-3.0.jar”放置在项目的lib文件夹中并进行了部署? If YES try placing the JAR in TOMCAT's LIB folder "C:\\Program Files\\Apache Software Foundation\\Tomcat 7.0\\lib" and check once.
如果是,请尝试将JAR放在TOMCAT的LIB文件夹“ C:\\ Program Files \\ Apache Software Foundation \\ Tomcat 7.0 \\ lib”中,然后检查一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.