Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java I';我试图通过MacOSX上的JDBC连接mysql_Java_Mysql_Eclipse_Macos_Jdbc - Fatal编程技术网

Java I';我试图通过MacOSX上的JDBC连接mysql

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

我的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的

您必须右键单击项目,选择
javabuildpath>Libraries
并添加一个JAR文件。对于MySQL,您需要


这不是在Eclipse中将JAR添加到类路径的方式

您必须右键单击项目,选择
javabuildpath>Libraries
并添加一个JAR文件。对于MySQL,您需要