Java“找不到符号”

时间:2019-12-03 22:17:25

标签: java

我正在尝试为医院预约系统编写代码。该程序给我一个错误,提示我在con.prepareStatement(找不到符号)中该怎么办。一旦他们被添加到mysql中的数据库中,我就应该使用医生的名字进行更新,然后我可以与特定的医生预约

    public class ManageAppointments extends javax.swing.JFrame {
       Appointments app = new Appointments();
        MyConnection con = new MyConnection();
        public ManageAppointments() {
            initComponents();
            LoadDoctor();
    }
    public class Doctors{
       String ID;
       String name;

       public Doctors (String ID, String name){
           this.ID = ID;
           this.name = name;
       }

       public String toString(){
           return name;
       }

   }
    public void LoadDoctor(){
       PreparedStatement ps= con.prepareStatement("select * from specification");
       ResultSet rs;

       try {
           rs= ps.executeQuery();
           jComboBox1.removeAll();

           while(rs.next())
           {
               jComboBox1.addItem(new Doctors(rs.getString(1),rs.getString(2)));

           }               


       } catch (SQLException ex) {
           Logger.getLogger(Appointments.class.getName()).log(Level.SEVERE, null, ex);
       }
   }



package hospitalmanagement;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class MyConnection {
   public Connection createConnection(){
       Connection con = null;

       MysqlDataSource mds = new MysqlDataSource();

       mds.setServerName("localhost");
       mds.setPortNumber(3306);
       mds.setUser("root");
       mds.setPassword("");
       mds.setDatabaseName("hospitalmanagement");

       try {
           con = mds.getConnection();
       } catch (SQLException ex) {
           Logger.getLogger(MyConnection.class.getName()).log(Level.SEVERE, null, ex);
       }
       return con ;
   }



}

0 个答案:

没有答案