本人亲自做的,不需要做任何修改即可顺利运行,sql表也与程序无缝连接,没有未识别部分。
Sql 表如下:CREATE TABLE STU(学号varchar(14) PRIMARY KEY,姓名varchar(8) NOT NULL,密码varchar(8) NOT NULL,班级varchar(14) NOT NULL ,性别varchar(2),学校varchar(14) NOT NULL);CREATE TABLE TCH(用户名varchar(8) NOT NULL,密码varchar(8) NOT NULL);CREATE TABLE 成绩表(学号varchar(14) PRIMARY KEY,计算机网络varchar(8) NOT NULL,汽车概论varchar(8) NOT NULL,初级日语varchar(8) NOT NULL,接口技术varchar(8) NOT NULL,ava程序设计varchar(8) NOT NULL,数据库varchar(8) NOT NULL,大学物理varchar(8) NOT NULL);源程序代码:import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class systems extends JFrame implements ActionListener{static systems ss;JPanel panel = new JPanel();JLabel label1 = new JLabel("输入姓名:");JTextField name = new JTextField();JLabel label2 = new JLabel("密码:");JPasswordField pwd = new JPasswordField();JButton Enter = new JButton("登录");JButton Exit = new JButton("退出");String url = "D:\\Systems\\title.jpg";ButtonGroup bgp = new ButtonGroup();JRadioButton stu = new JRadioButton("学生");JRadioButton tch = new JRadioButton("教师");public systems(){super("登录系统");this.setResizable(false);JLabel img = new JLabel(new ImageIcon(url));img.setBounds(0,0,500,100);panel.add(img);stu.setBounds(165,210,70,20);tch.setBounds(265,210,70,20);bgp.add(stu);bgp.add(tch);panel.add(stu);panel.add(tch);Enter.setBounds(150,250,80,20);Exit.setBounds(270,250,80,20);Enter.addActionListener(this);Exit.addActionListener(this);panel.add(Enter);panel.add(Exit);panel.setLayout(null);this.add(panel);label1.setBounds(135,130,100,25);panel.add(label1);name.setBounds(265,130,100,25);panel.add(name);label2.setBounds(135,165,100,25);panel.add(label2);pwd.setBounds(265,165,100,25);panel.add(pwd);this.setBounds(100,100,500,350);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }public void actionPerformed(ActionEvent e){if(e.getSource()==Enter){String username , password;username = name.getText();password = pwd.getText();try{Class.forName("oracle.jdbc.driver.OracleDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(ss,ce.getMessage());}if(stu.isSelected()){try{Connection con = DriverManager.getConnection("jdbc:oracle:thin:@user29:1521:XE","hr","oracle");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from STU");while(rs.next()){if((rs.getString("学号").equals(username))&&(rs.getString("密码").equals(password))){JOptionPane.showMessageDialog(ss,"登陆成功");Students stu = new Students();}else{JOptionPane.showMessageDialog(ss,"登录失败");}}rs.close();stmt.close();}catch (SQLException se){JOptionPane.showMessageDialog(ss,se.getMessage());}}else if(tch.isSelected()){try{Connection con = DriverManager.getConnection("jdbc:oracle:thin:@user29:1521:XE","hr","oracle");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from TCH");while(rs.next()){if((rs.getString("用户名").equals(username))&&(rs.getString("密码").equals(password))){JOptionPane.showMessageDialog(ss,"登陆成功");}else{JOptionPane.showMessageDialog(ss,"登录失败");}}}catch (SQLException se){JOptionPane.showMessageDialog(ss,se.getMessage());}}}else{System.exit(0);}}public static void main(String[] args){systems sys = new systems();}}import java.awt.*;import javax.swing.*;import java.awt.event.*;public class Students extends JFrame implements ActionListener{JMenuBar jmb = new JMenuBar();JMenu Message = new JMenu("信息");JMenu Score = new JMenu("成绩");JMenuItem Item1 = new JMenuItem("插入");JMenuItem Item2 = new JMenuItem("查询");JMenuItem Item3 = new JMenuItem("查询");public Students(){super("学生界面");this.setSize(500,400);this.setVisible(true);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setJMenuBar(jmb);jmb.add(Message);jmb.add(Score);Message.add(Item1);Message.add(Item2);Score.add(Item3);Item1.addActionListener(this);Item2.addActionListener(this);Item3.addActionListener(this);}public void actionPerformed(ActionEvent e){if(e.getSource()==Item1){AddMsg ad = new AddMsg();}else if(e.getSource()==Item2){Serch ser = new Serch();}else{}}public static void main(String[] args){Students stu = new Students();}}import java.awt.*;import javax.swing.*;import java.awt.event.*;public class Teachers extends JFrame implements ActionListener {JMenuBar bar = new JMenuBar();JMenu menu1 = new JMenu("信息");JMenu menu2 = new JMenu("成绩");JMenuItem item1 = new JMenuItem("录入信息");JMenuItem item2 = new JMenuItem("录入成绩");JPanel jpl = new JPanel();public Teachers(){super("教师界面");this.setSize(500,300);this.setResizable(false);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setJMenuBar(bar);this.add(jpl);jpl.setLayout(null);bar.add(menu1);bar.add(menu2);menu1.add(item1);menu2.add(item2);item1.addActionListener(this);item2.addActionListener(this);}public void actionPerformed(ActionEvent e){if(e.getSource()==item1){AddMsg msg = new AddMsg();}else{Addscore as = new Addscore();}}public static void main(String[] args){Teachers tch = new Teachers();}}import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class Serch extends JFrame implements ActionListener{/*查询学生信息控件*/static Serch s;JPanel jpl = new JPanel();JLabel SCH = new JLabel("查询学生信息",JLabel.CENTER);JLabel label1 = new JLabel("请输入学号:",JLabel.CENTER);JButton serch = new JButton("查询");JLabel label2 = new JLabel("姓名:",JLabel.CENTER);JLabel label3 = new JLabel("班级:",JLabel.CENTER);JLabel label4 = new JLabel("学校:",JLabel.CENTER);JLabel label5 = new JLabel("性别:",JLabel.CENTER);ButtonGroup bgp = new ButtonGroup();JRadioButton man = new JRadioButton("男");JRadioButton women = new JRadioButton("女");JTextField num = new JTextField();JTextField nam = new JTextField();JTextField clas = new JTextField();JTextField scl = new JTextField();JButton reset = new JButton("重置");public Serch(){this.setSize(500,400);this.setVisible(true);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.add(jpl);jpl.setLayout(null);serch.addActionListener(this);reset.addActionListener(this);/*查询面板*/SCH.setBounds(100,20,300,20);jpl.add(SCH);label1.setBounds(100,60,100,20);jpl.add(label1);num.setBounds(220,60,140,20);jpl.add(num);serch.setBounds(120,100,90,20);reset.setBounds(260,100,90,20);jpl.add(serch);jpl.add(reset);label2.setBounds(100,140,70,20);jpl.add(label2);nam.setBounds(190,140,140,20);jpl.add(nam);label5.setBounds(100,180,70,20);jpl.add(label5);man.setBounds(205,180,60,20);women.setBounds(285,180,60,20);bgp.add(man);bgp.add(women);jpl.add(man);jpl.add(women);label3.setBounds(100,220,70,20);jpl.add(label3);clas.setBounds(190,220,140,20);jpl.add(clas);label4.setBounds(100,260,70,20);jpl.add(label4);scl.setBounds(190,260,140,20);jpl.add(scl);}public void actionPerformed(ActionEvent e){String id = num.getText();if(e.getSource()==serch){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");Statement stmt = con.createStatement();ResultSet rs = stmt.executeQuery("select * from STU where ID = '" + id +"'");while(rs.next()){nam.setText(rs.getString("Name"));if(rs.getString("Sex").equals("男")){man.setSelected(true);}else{women.setSelected(true);}clas.setText(rs.getString("Class"));scl.setText(rs.getString("Collage"));}}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}}public static void main(String[] args){Serch sch = new Serch();}}import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class AddMsg extends JFrame implements ActionListener{static AddMsg s;/*添加学生信息控件*/JPanel jpl = new JPanel();JLabel label1 = new JLabel("添加基本信息",JLabel.CENTER);JLabel label2 = new JLabel("学号:",JLabel.CENTER);JLabel label3 = new JLabel("姓名:",JLabel.CENTER);JLabel label4 = new JLabel("性别:",JLabel.CENTER);JLabel label5 = new JLabel("班级:",JLabel.CENTER);JLabel label6 = new JLabel("学院:",JLabel.CENTER); JTextField num = new JTextField(2);JTextField nam = new JTextField(4);ButtonGroup bgp = new ButtonGroup();JRadioButton man = new JRadioButton("男");JRadioButton women = new JRadioButton("女");JTextField clas = new JTextField();JTextField scl = new JTextField();JButton reset = new JButton("重置");JButton addmsg = new JButton("添加");public AddMsg(){super("添加学生信息");this.setResizable(false);this.setSize(500,400);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.add(jpl);jpl.setLayout(null);addmsg.addActionListener(this);reset.addActionListener(this);/*插入面板*/label1.setBounds(100,20,300,20);jpl.add(label1);label2.setBounds(100,50,70,20);jpl.add(label2);num.setBounds(190,50,140,20);jpl.add(num);label3.setBounds(100,90,70,20);jpl.add(label3);nam.setBounds(190,90,140,20);jpl.add(nam);label4.setBounds(100,130,70,20);jpl.add(label4);man.setBounds(190,130,60,20);women.setBounds(270,130,60,20);jpl.add(man);jpl.add(women);bgp.add(man);bgp.add(women);label5.setBounds(100,170,70,20);jpl.add(label5);clas.setBounds(190,170,140,20);jpl.add(clas);label6.setBounds(100,210,70,20);jpl.add(label6);scl.setBounds(190,210,140,20);jpl.add(scl);reset.setBounds(120,250,90,20);addmsg.setBounds(240,250,90,20);jpl.add(reset);jpl.add(addmsg);}public void actionPerformed(ActionEvent e){if(e.getSource()==addmsg){String sex;if(man.isSelected()){sex="男";}else{sex="女";}try{Class.forName("oracle.jdbc.driver.OracleDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(s,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:oracle:thin:@user29:1521:XE","hr","oracle");Statement stmt = con.createStatement();int a = stmt.executeUpdate("insert into STU(ID , Pwd , Name , Sex , Class , Collage)values('"+num.getText()+"','"+"12345678','"+nam.getText()+"','"+sex+"','"+clas.getText() +"','"+scl.getText()+"')");if(a==1){JOptionPane.showMessageDialog(s,"已成功添加");}else{JOptionPane.showMessageDialog(s,"添加失败");}stmt.close();}catch (SQLException se){JOptionPane.showMessageDialog(s,se.getMessage());}}else{num.setText("");nam.setText("");clas.setText("");scl.setText("");num.requestFocus();}}public static void main(String[] args){AddMsg amg = new AddMsg();}}import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.sql.*;public class Addscore extends JFrame implements ActionListener{static Addscore ss;JLabel[] label = {new JLabel("学号:") , new JLabel("计算机网络:") , new JLabel("汽车概论:") , new JLabel("初级日语:") , new JLabel("接口技术:") , new JLabel("Java程序设计:") , new JLabel("数据库:") , new JLabel("算法设计:") , new JLabel("大学物理:")};JTextField[] txt = {new JTextField() , new JTextField() , new JTextField() , new JTextField() , new JTextField() ,new JTextField() , new JTextField() ,new JTextField() ,new JTextField() };JButton add = new JButton("添加");JButton reset = new JButton("重置");JPanel jpl = new JPanel();JLabel title = new JLabel("添加学生成绩" , JLabel.CENTER); Font f = new Font("黑体" , Font.BOLD , 16 );int s = 100;public Addscore(){super("添加学生信息");this.setResizable(false);this.setSize(500,600);this.setDefaultCloseOperation(EXIT_ON_CLOSE);this.setVisible(true);this.add(jpl);add.addActionListener(this);reset.addActionListener(this);jpl.setLayout(null);title.setBounds(150,40,200,20);title.setFont(f);title.setForeground(Color.red);jpl.setBackground(Color.LIGHT_GRAY);jpl.add(title);for(int i = 0 ; i <label.length ; i++){label[i].setBounds(100,s,140,20);jpl.add(label[i]);txt[i].setBounds(260,s,140,20);jpl.add(txt[i]);s=s+40;}add.setBounds(150,s,80,20);reset.setBounds(250,s,80,20);jpl.add(add);jpl.add(reset);}public void actionPerformed(ActionEvent e){if(e.getSource()==add){try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch (ClassNotFoundException ce){JOptionPane.showMessageDialog(ss,ce.getMessage());}try{Connection con = DriverManager.getConnection("jdbc:odbc:sysdb","sa","");Statement stmt = con.createStatement();int a = stmt.executeUpdate("insert into 计算机系成绩(SID , 计算机网络,汽车概论, 初级日语, 接口技术, Java程序设计, 数据库, 算法设计, 大学物理)values('"+txt[0].getText()+"','"+txt[1].getText()+"','"+txt[2].getText()+"','"+txt[3].getText()+"','" +txt[4].getText()+"','"+txt[5].getText()+"','"+txt[6].getText()+"','"+txt[7].getText()+"','"+txt[8].getT ext()+"')");if(a==1){JOptionPane.showMessageDialog(ss,"添加成功");}else{JOptionPane.showMessageDialog(ss,"添加失败");}}catch (SQLException se){JOptionPane.showMessageDialog(ss,se.getMessage());}}else{for(int i = 0 ; i<txt.length ; i++){txt[i].setText("");txt[0].requestFocus();}}}public static void main(String[] args){Addscore as = new Addscore();}}。