[英]ClassNotFoundException when I'm trying to connect jdbc, odbc
[英]I'm trying to connect mysql through JDBC on mac osx
我的IDE是Eclipse Indigo。 當我嘗試連接時收到此消息:
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
但是我仍然有例外。
這不是在Eclipse中將JAR添加到類路徑的方式。
您必須右鍵單擊您的項目,選擇Java Build Path > Libraries
並添加一個JAR文件。 對於MySQL,您需要MySQL Connector J。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.