我試圖設置一個mySQL連接器,我不確定發生了什麼問題。以下是錯誤:barebones mySQL java連接器問題
SQLException: No suitable driver found for jdbc:mysql://localhost/db?user=root&password=
這是我的java:
// ESTABLISH DRIVER INSTANCE
try {
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
// ESTABLISH DB CONNECTION
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/db?" +
"user="+user+"&password="+pass);
// Do something with the Connection
//
//
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
這裏是我的build.xml:
<project>
<target name="run">
<javac srcdir="." destdir=".">
<classpath>
<pathelement path="./mysql-connector-java-5.1.38i/mysql-connector-java-5.1.38-bin.jar"/>
<pathelement location="./DB_Test.class"/>
</classpath>
</javac>
<java classname="DB_Test">
<classpath>
<pathelement path="./mysql-connector-java-5.1.38i/mysql-connector-java-5.1.38-bin.jar"/>
<pathelement location="."/>
</classpath>
</java>
</target>
</project>
我認爲這個問題很可能是在構建。 XML,因爲我對螞蟻很不熟悉。我不確定這兩種「途徑」是否必要,或者其中任何一個是否有效。我想知道如果我需要爲這個罐子食用日食。
我也認爲我的連接URL語法可能存在問題。 「db」是連接的名字嗎?或架構?我的本地主機後需要端口號嗎?
不能對全球的解決方案幫助,但對URL語法:「DB」是連接到數據庫,如果你不提供端口號,則默認爲3306(見https://開頭docs.oracle.com/javase/tutorial/jdbc/basics/connecting.html)。 –