基本上我正在尝试将我的 eclipse 连接到 JDBC,我已经将 jdbcsql 的外部路径添加到我的 eclipse 中。
当我在 Eclipse 中的代码中运行 java 时,到目前为止我遇到了这个错误:
Exception in thread "main" java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at insertion.insert_values(insertion.java:12)
第 12 行与此行相反:
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER","sa","password");
我使用我的 JDBC SA 帐户,这部分 Java 代码将我的 eclipse 连接到 JDBC 驱动程序:
Connection con = null; PreparedStatement statement = null; //to take care of the sql statements to be run
//Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=MASTER","sa","ronpaul");
是我的 URL 或代码语法有问题,还是我没有以正确的方式将外部 jar 添加到我的 Eclipse 中?
我已经将最后一个 JDBC 驱动程序添加到我的 java 包路径中,那么是什么导致了错误?第 12 行可能有代码语法错误?
最佳答案
Is the problem with my URL
是的。 Microsoft 的 SQL Server JDBC 驱动程序使用 URL 前缀
jdbc:sqlserver://...
不是
jdbc:microsoft:sqlserver://...
请参阅 MSDN 文档 Building the Connection URL了解详情。
关于java - 收到 "no suitable driver found for..."JDBC 错误,但我已经将 jar 添加到我的 Eclipse 路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42940744/