當(dāng)我嘗試運(yùn)行此程序時(shí),出現(xiàn)此異常。這是微軟的例子之一。我已經(jīng)通過項(xiàng)目屬性將sqljdbc4.jar添加到了netbeans的類路徑中,以便進(jìn)行編譯和運(yùn)行。我還測試了可以使用下面的import語句找到該類-編譯期間沒有錯(cuò)誤,因此它必須找到j(luò)ar??赡芘csqldbc4.jar引用的dll或某些sql dll相關(guān)嗎?這是確切的例外,下面是確切的代碼(密碼除外)。例外:run:java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databaseName=HealthCareDatabaseError Trace in getConnection() : No suitable driver found for jdbc:microsoft:sqlserver://localhost:1433;databaseName=HealthCareDatabaseError: No active Connection at java.sql.DriverManager.getConnection(DriverManager.java:602) at java.sql.DriverManager.getConnection(DriverManager.java:185) at javaapplication1.Connect.getConnection(Connect.java:35) at javaapplication1.Connect.displayDbProperties(Connect.java:50) at javaapplication1.JavaApplication1.main(JavaApplication1.java:23)BUILD SUCCESSFUL (total time: 1 second)碼: package javaapplication1;import com.microsoft.sqlserver.jdbc.SQLServerDriver;import java.*;public class Connect { private java.sql.Connection con = null; private final String url = "jdbc:microsoft:sqlserver://"; private final String serverName = "localhost"; private final String portNumber = "1433"; private final String databaseName = "HealthCareDatabase"; private final String userName = "larry"; private final String password = "xxxxxxx"; // Constructor public Connect() { } private String getConnectionUrl() { return url + serverName + ":" + portNumber + ";databaseName=" + databaseName ; }
java.sql.SQLException:找不到適用于jdbc:microsoft:
HUWWW
2019-10-31 12:37:22