我在Mac OS X上安裝了Eclipse Indigo,並且已經下載了mysql連接器(版本5.1)。
我添加的jar到項目中,我使用這個代碼:當我嘗試執行程序中,我得到這個例外獲取mysql和java一起工作
public class Test
{
public static void main (String[] args)
{
try {
String url = "jdbc:msql://200.210.220.1:1114/Demo";
Connection conn = DriverManager.getConnection(url,"","");
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT Lname FROM Customers WHERE Snum = 2001");
while (rs.next()) {
String lastName = rs.getString("Lname");
System.out.println(lastName);
}
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
:
Got an exception!
No suitable driver found for jdbc:msql://200.210.220.1:1114/Demo
我的問題是:如何安裝司機?我還應該做什麼?
並且一旦安裝了驅動程序,我該如何獲取我的數據庫URL(我正在使用mysql 5.5)?
我還沒有在網上找到有效的指南,它們都太具體。
http://stackoverflow.com/questions/8146793/jdbc-msql-no-suitable-driver-found-for-jdbcmysql-localhost3306-mysql –
這個答案是更好 - http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql/2840358#2840358 –