MySQL - SQLException:没有为jdbc找到合适的驱动程序:derby://

时间:2016-01-03 22:19:14

标签: java mysql

我是一个编程菜鸟,所以请温柔地对待我; _;

基本上 - 我创建了一个MySQL Java数据库,我收到了这个错误:

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/StudentScores

错误在编辑期间仅在我运行时出现,填写详细信息并单击"添加学生" (数据库存储学生的考试成绩详情)

这里是代码

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    try
    {
        String url = "jdbc:derby://localhost:1527/StudentScores ";
        String username = "admin3";
        String password = "admin3";

        Connection con = DriverManager.getConnection(url, username, password);
        Statement stmt = con.createStatement();
        String Query = "INSERT INTO STUDENT (NAME, DATEOFQUIZ, MEMORYSCORE, COMPREHENSIONSCORE, PROBLEMSOLVINGSCORE, AVERAGEPERCENTAGE) VALUES ('"+NameText.getText()+"','"+DateText.getValue()+"','"+MemoryScoreText.getText()+"','"+ComprehensionScoreText.getText()+"','"+ProblemSolvingScoreText.getText()+"', '"+AveragePercentageText.getText()+"')";

        JOptionPane.showMessageDialog(null, "Student Added");

        NameText.setText(null);
        DateText.setText("00/00/0000");
        MemoryScoreText.setText(null);
        ComprehensionScoreText.setText(null);
        ProblemSolvingScoreText.setText(null);
        AveragePercentageText.setText(null);

    }
    catch(SQLException ex)
    {
       JOptionPane.showMessageDialog(null, ex.toString());
    }
}  

帮帮我吗?谢谢:))

1 个答案:

答案 0 :(得分:3)

您正在尝试加载Derby驱动程序,而不是MySQL的驱动程序。你的JDBC网址应该是

jdbc:mysql://localhost:3306/StudentScores

代替。如果在修复之后仍然遇到相同的异常,那么您需要确保MySQL驱动程序jar文件位于类路径中。