Java I';我试图通过MacOSX上的JDBC连接mysql
我的IDE是Eclipse Indigo。当我尝试连接时,我发现:Java I';我试图通过MacOSX上的JDBC连接mysql,java,mysql,eclipse,macos,jdbc,Java,Mysql,Eclipse,Macos,Jdbc,我的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"; Connect
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的 您必须右键单击项目,选择
javabuildpath>Libraries
并添加一个JAR文件。对于MySQL,您需要
这不是在Eclipse中将JAR添加到类路径的方式 您必须右键单击项目,选择
javabuildpath>Libraries
并添加一个JAR文件。对于MySQL,您需要