1
我的IDE是Eclipse Indigo。當我試圖連接時,我得到這個:我想通過在mac osx上的JDBC連接mysql
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
這裏是我的代碼。
public class TPCH
{
public static void main(String[] args)
{
String userName = "tpch";
String password = "tpch";
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put("user", userName);
connectionProps.put("password", password);
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (Exception e)
{
e.printStackTrace();
}
try {
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/",
connectionProps);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println("Error connecting to db");
}
}
}
我覺得JDBC沒有導入。我試圖通過導入它
preference -> java -> build path -> user library -> add jars
但我仍然有這種例外。
您添加了哪個JAR? – adarshr
你有什麼異常? – isvforall