[英]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.