1.成绩录入packagestudentManage;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.*;publicclassStudentManageSystemextendsJFrame{JTextFieldjtfdID=newJTextField(8);JTextFieldjtfdName=newJTextField(128);JTextFieldjtfdSex=newJTextField(128);JTextFieldjtfdAge=newJTextField(8);publicStudentManageSystem(){JButtonjbtnEnter=newJButton(录入);JButtonjbtnClear=newJButton(清零);JLabeljlblID=newJLabel(学号);JLabeljlblName=newJLabel(姓名);JLabeljlblSex=newJLabel(性别);JLabeljlblAge=newJLabel(年龄);setLayout(newGridLayout(5,2,5,5));add(jlblID);add(jtfdID);add(jlblName);add(jtfdName);add(jlblSex);add(jtfdSex);add(jlblAge);add(jtfdAge);add(jbtnEnter);add(jbtnClear);jbtnEnter.addActionListener(newEnterListener());jbtnClear.addActionListener(newClearListener());}classEnterListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){Booleanrs=null;try{Class.forName(com.mysql.jdbc.Driver);Connectionconn=DriverManager.getConnection(jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8,root1,root);Statementstmt=conn.createStatement();Stringsql=insertintostudentvalues('+jtfdID.getText()+','+jtfdName.getText()+','+jtfdSex.getText()+','+jtfdAge.getText()+');stmt.execute(sql);jtfdID.setText();jtfdName.setText();jtfdSex.setText();jtfdAge.setText();}catch(ClassNotFoundExceptione2){System.out.println(Sorry,can'tfindtheDriver!);e2.printStackTrace();}catch(SQLExceptione3){e3.printStackTrace();}catch(Exceptione4){e4.printStackTrace();}}}classClearListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){jtfdID.setText();jtfdName.setText();jtfdSex.setText();jtfdAge.setText();}}publicstaticvoidmain(String[]args){StudentManageSystems=newStudentManageSystem();s.setTitle(学生个人信息录入);s.setSize(400,300);s.setLocationRelativeTo(null);s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);s.setVisible(true);}}2.成绩查询importjava.awt.BorderLayout;importjava.awt.FlowLayout;importjava.awt.GridLayout;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.swing.JButton;importjavax.swing.JComboBox;importjavax.swing.JFrame;importjavax.swing.JPanel;importjavax.swing.JTextField;importcom.mysql.jdbc.PreparedStatement;publicclassSearchextendsJFrame{JComboBoxjcbSelect=newJComboBox();JTextFieldjtfdInput=newJTextField();JButtonjbtnSearch=newJButton(查询);Stringslt=null;//确定下拉框所选的内容publicSearch(){jcbSelect.addItem(学号);jcbSelect.addItem(姓名);jcbSelect.addItem(性别);jcbSelect.addItem(年龄);JPaneljpl1=newJPanel(newGridLayout(2,1));//setLayout(newGridLayout(2,1));jpl1.add(jcbSelect);jpl1.add(jtfdInput);setLayout(newGridLayout(2,1));add(jpl1);add(jbtnSearch);jbtnSearch.addActionListener(newSearchListener());if(jcbSelect.getSelectedItem()==学号){slt=Sno;}elseif(jcbSelect.getSelectedItem()==姓名){slt=Sname;}elseif(jcbSelect.getSelectedItem()==性别){slt=Ssex;}else{slt=Sage;}}classSearchListenerimplementsActionListener{publicvoidactionPerformed(ActionEvente){ResultSetrs=null;try{Class.forName(com.mysql.jdbc.Driver);Connectionconn=DriverManager.getConnection(jdbc:mysql://127.0.0.1:3306/test,root1,root);//PreparedStatementps=conn.prepareStatement(select*fromstudentwhere+slt+like'%?%');Statementstmt=conn.createStatement();Stringsql=select*fromstudentwhere+slt+=+jtfdInput.getText();rs=stmt.executeQuery(sql);}catch(ClassNotFoundExceptione2){System.out.println(Sorry,can'tfindtheDriver!);e2.printStackTrace();}catch(SQLExceptione3){e3.printStackTrace();}catch(Exceptione4){e4.printStackTrace();}{try{while(rs.next()){System.out.println(rs.getString(1)+\t+rs.getString(2)+\t+rs.getString(3)+\t+rs.getInt(4));}}catch(SQLExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}//while循环输出结果}}}publicstaticvoidmain(String[]args){Searchs=newSearch();s.setTitle(学生个人信息查询);s.setSize(300,200);s.setLocationRelativeTo(null);s.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);s.setVisible(true);}}