0

可能重复:
无法加载 com.mysql.jdbc.Driver

您好,我正在尝试更新我的表格,但连接一直失败。以下是我的代码:

try {
            String driver = "com.mysql.jdbc.Driver";
            Class.forName(driver).newInstance();
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql?zeroDateTimeBehavior=convertToNull","root","P@typd79");
            Statement stmt = con.createStatement();
            String query = "INSERT INTO project_one.personal_info(ssn,name,street,city,state,zip,class,degree,s,imm) VALUES"
                    + "(" + social + "," + Name + "," + Address + "," + City + "," + State + "," + Zip
                    + "," + Year + "," + Degree + "," + HS + "," + IMM + ")";

            stmt.executeUpdate(query);
            JOptionPane.showMessageDialog(null, "New student added successfully");

        } catch (Exception e) {

            JOptionPane.showMessageDialog(null,"Data not saved: " + e,"Error",JOptionPane.ERROR_MESSAGE);

        } 

    }

连接名称和驱动程序正确,但出现以下错误java.lang.classnotfound.exeption:com.mysql.jdbc.Driver.

我错过了什么?

4

3 回答 3

0

看起来你缺少 jdbc jar。

于 2012-10-03T12:58:15.663 回答
0

您应该将 mysql 驱动程序 jar 添加到您的构建路径。

于 2012-10-03T12:59:33.710 回答
0

从http://dev.mysql.com/downloads/connector/j/添加 jdbc mysql 驱动程序

于 2012-10-03T13:00:56.893 回答