首页 > 解决方案 > 通过 Netbeans 使用 mysql 时出现意外错误

问题描述

这是我的源代码,没有错误。我无法弄清楚出了什么问题。它给出了一个意想不到的错误,说“java.sql.driver”,我不知道该怎么做。

String v=jTextField1.getText();
    DefaultTable DefaultTableModel = null;
    DefaultTable model;
    model = (DefaultTableModel);
    jTable1.getModel();
    try
            {
            Class.forName("java.sql.driver"); 
            Connection c;
            c=DriverManager.getConnection("jdbc:mysql://local host/hospital","root","hope");
            Statement s=c.createStatement();

            String q;
        q = ("Select * from hospital where Patient_Name=v");

            ResultSet r=s.executeQuery(q);
            while(r.next())
            {
                int PNO=r.getInt("PNO");
                String Patient_Name=r.getString("Patient_Name");
                int Age=r.getInt("Age");
                String Gender=r.getString("Gender");
                String Department=r.getString("Department");
                String Doctor=r.getString("Doctor");
                model.addRow(new Object[]
                {PNO,Patient_Name,Age,Gender,Department,Doctor});


                r.close();
                s.close();
                e.close();
            }
            }catch (ClassNotFoundException e)
            {
                JOptionPane.showMessageDialog(null,e.getMessage());
            } catch (SQLException e) {
                JOptionPane.showMessageDialog(null,e.getMessage());
    }

标签: javamysqlnetbeans

解决方案


推荐阅读