2022.6.9 更新
这个课程作业的代码有小伙伴反馈有问题(数据库无法连接等),但博主最近学业不用Java了,暂时没时间看,如果有同学有解决方案,可以在下面评论帮助一下其他同学。实在抱歉啦。


package shujuku;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;import java.util.*;
import java.sql.*;
import javax.swing.table.*;class allstudent extends JFrame implements ActionListener {JMenu jm = new JMenu("信息");JMenuItem j1 = new JMenuItem("显示信息");JMenuItem j2 = new JMenuItem("退出");JMenuBar JBar = new JMenuBar();allstudent() {super("学生信息记录表");setSize(540, 400);setLocation(320, 240);//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);JBar.add(jm);jm.add(j1);jm.add(j2);setJMenuBar(JBar);j1.addActionListener(this);j2.addActionListener(this);setVisible(true);}public void actionPerformed(ActionEvent e) {if (e.getSource() == j2)this.dispose();else if (e.getSource() == j1) {int i, j, row;try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException ce) {}try {Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager", "sa", "123456");Statement stm = con.createStatement();ResultSet rs = stm.executeQuery("select * from info");displayResultSet(rs);rs.close();stm.close();//con.close();} catch (SQLException se) {}}}public void displayResultSet(ResultSet rs) throws SQLException {boolean moreRecords = rs.next();if (!moreRecords) {JOptionPane.showMessageDialog(null, "结果无记录", "无记录", JOptionPane.INFORMATION_MESSAGE);//return;}Vector rows = new Vector();Vector columnHeads = new Vector();try {ResultSetMetaData rsmd = rs.getMetaData();for (int i = 1; i <= rsmd.getColumnCount(); i++)columnHeads.addElement(rsmd.getColumnName(i));do {rows.addElement(getNextRow(rs, rsmd));} while (rs.next());JTable table = new JTable(rows, columnHeads);table.setSize(new Dimension(400, 400));JScrollPane scroller = new JScrollPane(table);Container c = getContentPane();c.add(scroller, BorderLayout.CENTER);c.validate();} catch (SQLException e) {e.printStackTrace();}}private Vector getNextRow(ResultSet rs, ResultSetMetaData rsmd) throws SQLException {Vector currentRow = new Vector();for (int i = 1; i <= rsmd.getColumnCount(); i++)currentRow.addElement(rs.getString(i));return currentRow;}// public static void main(String[] args) {//      new allstudent();
//  }
}
/** 功能:用来和数据库SQLserver进行连接,以及相应的查询方法。*/
package shujuku;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;//写一个类,用来与数据库建立连接,并且查询数据
class GetSQL {// 设定用户名和密码static String userword;static String pwd;static String english;static String num;static String name;static String chinese;static String zhengzhi;static String math;static String age;static String salary;static String sex;static String zhicheng;static String teanum;static String teaname;static Connection ct = null;static PreparedStatement ps = null;static ResultSet rs = null;// 用于连接数据库的方法,可用于子类的继承public static void ConnectSQL() {try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");ct = DriverManager.getConnection( "jdbc:sqlserver://localhost:1433;databaseName=StudentManager","sa","123456");System.out.println("The SQL is connected");} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}// 用于向数据库进行查询的方法public static void querystu(String s,String username) {// 创建火箭车try { ps = ct.prepareStatement("select * from info where 权限=? and 用户名=? ");// 给?赋值(可防止SQL注入漏洞问题),不要直接使用拼接的方式ps.setString(1, s);ps.setString(2, username);// ResultSet结果集,可以把ResultSet理解成返回一张表行的结果集rs = ps.executeQuery();// 循环取出if (rs.next()) {// 将教师的用户名和密码取出userword = rs.getString(2);pwd = rs.getString(3);System.out.println("成功获取到密码和用户名from数据库");//System.out.println(userword + "\t" + pwd + "\t");}else{JOptionPane.showMessageDialog(null, "没有此用户,请重新输入!", "提示消息", JOptionPane.WARNING_MESSAGE);}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}//在教师表中进行查询public static void querytea(String s,String name ) {// 创建火箭车try {ps = ct.prepareStatement("select * from info_tea where 权限=? and 用户名=? ");// 给?赋值(可防止SQL注入漏洞问题),不要直接使用拼接的方式ps.setString(1, s);ps.setString(2, name);// ResultSet结果集,可以把ResultSet理解成返回一张表行的结果集rs = ps.executeQuery();// 循环取出if (rs.next()) {// 将教师的用户名和密码取出userword = rs.getString(2);pwd = rs.getString(3);System.out.println("成功获取到密码和用户名from数据库");//System.out.println(userword + "\t" + pwd + "\t");}else{JOptionPane.showMessageDialog(null, "没有此用户,请重新输入!", "提示消息", JOptionPane.WARNING_MESSAGE);}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}//从数据库中根据学号或者教工号来查询数据,并且填入表格。public static void getdatastu(String s) {// 创建火箭车try {ps = ct.prepareStatement("select * from info where 学号 =? ");// 给?赋值(可防止SQL注入漏洞问题),不要直接使用拼接的方式ps.setString(1, s);// ResultSet结果集,大家可以把ResultSet理解成返回一张表行的结果集rs = ps.executeQuery();if(rs.next()) {// 将学生的用户名和密码取出num = rs.getString(4);name = rs.getString(5);math = rs.getString(6);chinese = rs.getString(7);english = rs.getString(8);zhengzhi = rs.getString(9);}else{JOptionPane.showMessageDialog(null, "沒有此学生,请重新输入", "提示消息", JOptionPane.WARNING_MESSAGE);}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}public static void getdatatea(String s) {// 创建火箭车try {ps = ct.prepareStatement("select * from info_tea where 教师编号 =? ");// 给?赋值(可防止SQL注入漏洞问题),不要直接使用拼接的方式ps.setString(1, s);// ResultSet结果集,大家可以把ResultSet理解成返回一张表行的结果集rs = ps.executeQuery();if(rs.next()) {// 将教师的用户名和密码取出teanum = rs.getString(4);teaname = rs.getString(5);sex = rs.getString(6);salary = rs.getString(7);zhicheng = rs.getString(8);age = rs.getString(9);}else{JOptionPane.showMessageDialog(null, "沒有此教师,请重新输入", "提示消息", JOptionPane.WARNING_MESSAGE);}} catch (Exception e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}}

package shujuku;import javax.swing.*;import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;public class Login extends JFrame implements ActionListener {// 定义登录界面的组件JButton jb1, jb2, jb3 = null;JRadioButton jrb1, jrb2 = null;JPanel jp1, jp2, jp3, jp4 = null;JTextField jtf = null;JLabel jlb1, jlb2, jlb3 = null;JPasswordField jpf = null;ButtonGroup bg = null;// 菜单项JMenuBar jmb = null;JMenu jm = null;JMenuItem jmi1, jmi2 = null;public static void main(String[] args) {// TODO Auto-generated method stubLogin ms = new Login();}// 构造函数public Login() {// 创建组件jb1 = new JButton("登录");jb2 = new JButton("重置");jb3 = new JButton("退出");// 设置监听jb1.addActionListener(this);jb2.addActionListener(this);jb3.addActionListener(this);jmb = new JMenuBar(); // JMenuBar指菜单栏jm = new JMenu("选项"); // JMenu是菜单栏中的选项栏jmi1 = new JMenuItem("开始"); // JMenuItem指选项栏中的选项jmi2 = new JMenuItem("退出系统");jm.add(jmi1);jm.add(jmi2);jmb.add(jm);jrb1 = new JRadioButton("教师", true);jrb2 = new JRadioButton("学生");bg = new ButtonGroup();bg.add(jrb1);bg.add(jrb2);
//      jrb2.setSelected(true);jp1 = new JPanel();jp2 = new JPanel();jp3 = new JPanel();jp4 = new JPanel();jlb1 = new JLabel("用户名:");jlb2 = new JLabel("密    码:");jlb3 = new JLabel("权    限:");jtf = new JTextField(10);jpf = new JPasswordField(10);// 加入到JPanel中jp1.add(jlb1);jp1.add(jtf);jp2.add(jlb2);jp2.add(jpf);jp3.add(jlb3);jp3.add(jrb1);jp3.add(jrb2);jp4.add(jb1);jp4.add(jb2);jp4.add(jb3);// 加入JFrame中this.setJMenuBar(jmb);this.add(jp1);this.add(jp2);this.add(jp3);this.add(jp4);// 设置布局管理器this.setLayout(new GridLayout(4, 1));// 给窗口设置标题this.setTitle("学生成绩管理系统");// 设置窗体大小this.setSize(300, 250);// 设置窗体初始位置this.setLocation(200, 150);// 设置当关闭窗口时,保证JVM也退出this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 显示窗体this.setVisible(true);this.setResizable(true);}@Overridepublic void actionPerformed(ActionEvent e) {if (e.getActionCommand() == "退出") {System.exit(0);} else if (e.getActionCommand() == "登录") {if (!jtf.getText().isEmpty() && !jpf.getText().isEmpty()) {// 当点击登录按钮时,首先与数据库建立连接GetSQL.ConnectSQL();// 如果选中教师登录 if (jrb1.isSelected()) {GetSQL.querytea("教师", jtf.getText());// 首先判断是否存在该用户,即是否得到了密码if (GetSQL.pwd == null) {this.clear();} else {// 调用登录方法this.tealogin();}} else if (jrb2.isSelected()) // 学生在登录系统{GetSQL.querystu("学生", jtf.getText());// 首先判断是否存在该用户,即是否得到了密码if (GetSQL.pwd == null) {this.clear();} else {// 调用登录方法this.stulogin();}}} else if (jtf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入用户名", "提示消息", JOptionPane.WARNING_MESSAGE);this.clear();} else if (jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入密码", "提示消息", JOptionPane.WARNING_MESSAGE);this.clear();}} else if (e.getActionCommand() == "重置") {this.clear();}}// 清空文本框和密码框public void clear() {jtf.setText("");jpf.setText("");}// 学生登录判断方法public void stulogin() {if (GetSQL.pwd.equals(jpf.getText())) {//                  System.out.println("登录成功");JOptionPane.showMessageDialog(null, "登录成功!", "提示消息", JOptionPane.WARNING_MESSAGE);this.clear();// 关闭当前界面dispose();// 创建一个新界面Stu_UI ui = new Stu_UI();} else if (jtf.getText().isEmpty() && jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入用户名和密码!", "提示消息", JOptionPane.WARNING_MESSAGE);} else if (jtf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入用户名!", "提示消息", JOptionPane.WARNING_MESSAGE);} else if (jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入密码!", "提示消息", JOptionPane.WARNING_MESSAGE);} else {JOptionPane.showMessageDialog(null, "用户名或者密码错误!\n请重新输入", "提示消息", JOptionPane.ERROR_MESSAGE);// 清空输入框this.clear();}}// 教师登录判断方法public void tealogin() {if (GetSQL.pwd.equals(jpf.getText())) {//                  System.out.println("登录成功");JOptionPane.showMessageDialog(null, "登录成功!", "提示消息", JOptionPane.WARNING_MESSAGE);this.clear();// 关闭当前界面dispose();// 创建一个新界面,适用于教师来管理学生Teacher t = new Teacher();} else if (jtf.getText().isEmpty() && jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入用户名和密码!", "提示消息", JOptionPane.WARNING_MESSAGE);} else if (jtf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入用户名!", "提示消息", JOptionPane.WARNING_MESSAGE);} else if (jpf.getText().isEmpty()) {JOptionPane.showMessageDialog(null, "请输入密码!", "提示消息", JOptionPane.WARNING_MESSAGE);} else {JOptionPane.showMessageDialog(null, "用户名或者密码错误!\n请重新输入", "提示消息", JOptionPane.ERROR_MESSAGE);// 清空输入框this.clear();}}}
 /** 功能:学生登录成功界面。* */
package shujuku;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;import javax.swing.*;public class Stu_UI extends JFrame implements ActionListener
{//定义组件JMenuBar jm= new JMenuBar();JMenu jm1 = new JMenu("查询");JMenuItem jmi1 = new JMenuItem("基本信息");JMenu jm2 = new JMenu("修改");JMenuItem jmi2 = new JMenuItem("修改密码");//        public static void main(String[] args) {//          // TODO Auto-generated method stub
//          Stu_UI  ui=new Stu_UI();
//      }   //构造函数public  Stu_UI()    //不能申明为void!!!!!否则弹不出新界面{//创建组件this.setTitle("学生管理系统");this.setLayout(new CardLayout());this.setJMenuBar(jm);jm.add(jm1);   jm.add(jm2);   jm1.add(jmi1);  jm2.add(jmi2);  jmi1.addActionListener(this);jmi2.addActionListener(this);this.setSize(400,300);this.setLocation(200, 200);      this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);
}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif(e.getSource()==jmi1){find();}if(e.getSource()==jmi2){change();}}public void find(){final JDialog fontDialog = new JDialog(this, "基本信息", false);Container con = fontDialog.getContentPane();JPanel panel1 = new JPanel();panel1.setLayout(new GridLayout(5,2));JPanel panel2 = new JPanel();JLabel J1 = new JLabel("请输入学号:");final JTextField JT1 = new JTextField(15);JLabel math = new JLabel("数学:");final JTextField math1 = new JTextField(15);JLabel chinese = new JLabel("语文:");final JTextField chinese1 = new JTextField(15);JLabel eng = new JLabel("英语:");final JTextField eng1 = new JTextField(15);JLabel zhengzhi = new JLabel("政治:");final JTextField zhengzhi1 = new JTextField(15);JButton JB1 = new JButton("查询");panel1.add(J1);panel1.add(JT1);panel1.add(math);panel1.add(math1);panel1.add(chinese);panel1.add(chinese1);panel1.add(eng);panel1.add(eng1);panel1.add(zhengzhi);panel1.add(zhengzhi1);panel2.add(JB1);con.add(panel1);con.add(panel2);con.setLayout(new GridLayout(2,1));fontDialog.setSize(400, 400);fontDialog.setLocation(200, 200);fontDialog.setResizable(true);fontDialog.setVisible(true);JB1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");}catch (ClassNotFoundException ce){}try{Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager","sa","123456");Statement stm = con.createStatement();ResultSet rs = stm.executeQuery("select * from info where 学号= '" + JT1.getText()+ "'");if(rs.next()){math1.setText(rs.getString("数学"));chinese1.setText(rs.getString("语文"));eng1.setText(rs.getString("英语"));zhengzhi1.setText(rs.getString("政治"));}else {JOptionPane.showMessageDialog(null,"不存在该记录!");}}catch (SQLException se){JOptionPane.showMessageDialog(null,se.getMessage()); }}});}public void change(){final JDialog fontDialog = new JDialog(this, "修改个人密码", false);Container con = fontDialog.getContentPane();JPanel panel1 = new JPanel();panel1.setLayout(new GridLayout(4,2));JPanel panel2 = new JPanel();JLabel JLP = new JLabel("请输入你的学号:");final JTextField JTL = new JTextField();JLabel JLP1 = new JLabel("请输入原来密 码 : ");JPasswordField JTP1 = new JPasswordField();JLabel JLP2 = new JLabel("请输入新密 码 : ");JPasswordField JTP2 = new JPasswordField();JLabel JLP3 = new JLabel("请再次输入新密 码   : ");final JPasswordField JTP3 = new JPasswordField();JButton JB1 = new JButton("确定");JButton JB2 = new JButton("退出");panel1.add(JLP);panel1.add(JTL);panel1.add(JLP1);panel1.add(JTP1);panel1.add(JLP2);panel1.add(JTP2);panel1.add(JLP3);panel1.add(JTP3);panel2.add(JB1);panel2.add(JB2);con.setLayout(new GridLayout(2,1));con.add(panel1);con.add(panel2);fontDialog.setSize(400, 340);fontDialog.setLocation(200, 200);fontDialog.setResizable(false);fontDialog.setVisible(true);JB1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try{ JTL.setEditable(false);Connection cot = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager","sa","123456");Statement stmt = cot.createStatement();int a =   stmt.executeUpdate("Update info set 密码='"+JTP3.getText()+"'where 学号='"+JTL.getText()+"'");//System.out.print("成功了"); if(a==1){JOptionPane.showMessageDialog(null,"修改成功");}else{JOptionPane.showMessageDialog(null,"修改失败");}}catch(SQLException se){System.out.print("数据连接或修改失败"); }}});   }}

/** 功能:实现了查询修改删除学生的信息。*/
package shujuku;import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;public class Teacher extends JFrame implements ActionListener {// 定义组件JMenuBar mainMenu = new JMenuBar();JMenu menu1 = new JMenu("学生信息操作");JMenuItem itemAdd = new JMenuItem("添加学生信息");JMenuItem itemDel = new JMenuItem("删除学生信息");JMenuItem itemMod = new JMenuItem("修改学生信息");JMenu itemSel = new JMenu("查看学生信息");JMenuItem item1 = new JMenuItem("查看全部学生");JMenuItem item2 = new JMenuItem("查看指定学生");JPanel jp = new JPanel();// 构造函数public Teacher() {// 创建组件super("学生管理系统-老师界面");mainMenu.add(menu1);mainMenu.add(itemSel);menu1.add(itemAdd);menu1.add(itemDel);menu1.add(itemMod);//menu1.add(itemSel);itemSel.add(item1);itemSel.add(item2);itemAdd.addActionListener(this);itemDel.addActionListener(this);itemMod.addActionListener(this);itemSel.addActionListener(this);item1.addActionListener(this);item2.addActionListener(this);this.setSize(320, 240);this.setResizable(false);this.setVisible(true);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setJMenuBar(mainMenu);this.add(jp);this.setLayout(null);this.setTitle("学生成绩管理系统—教师");this.setSize(500, 500);this.setLocation(150, 150);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);this.setResizable(true);}public void Add() {final JDialog fontDialog = new JDialog(this, "添加学生信息", false);Container con = fontDialog.getContentPane();JPanel panel1 = new JPanel();panel1.setLayout(new GridLayout(4, 2));JPanel panel2 = new JPanel();JLabel JLNumber = new JLabel("学号:");final JTextField JTNumber = new JTextField(15);JLabel JLName = new JLabel("姓名:");final JTextField JTName = new JTextField(15);JLabel JLusername = new JLabel("用户名:");final JTextField JTuname = new JTextField(15);JLabel JLpassword = new JLabel("密码:");final JTextField JTpassword = new JTextField(15);JButton JBAdd = new JButton("添加");JButton JBNext = new JButton("重置");panel1.add(JLNumber);panel1.add(JTNumber);panel1.add(JLName);panel1.add(JTName);panel1.add(JLusername);panel1.add(JTuname);panel1.add(JLpassword);panel1.add(JTpassword);panel2.add(JBAdd);panel2.add(JBNext);con.setLayout(new GridLayout(2, 1));con.add(panel1);con.add(panel2);fontDialog.setSize(400, 340);fontDialog.setLocation(200, 200);fontDialog.setResizable(true);fontDialog.setVisible(true);JBAdd.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException ce) {JOptionPane.showMessageDialog(null, ce.getMessage());}try {Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager", "sa", "123456");Statement stm = con.createStatement();int a = stm.executeUpdate("insert into info(权限,用户名,密码,学号,姓名) "+" values ('学生'"+",'"+JTuname.getText()+"','"+JTpassword.getText()+"','"+JTNumber.getText()+"','"+JTName.getText()+"')");if (a == 1) {JOptionPane.showMessageDialog(null, "添加成功!");} else {JOptionPane.showMessageDialog(null, "添加失败!");}stm.close();} catch (Exception ee) {JOptionPane.showMessageDialog(null, ee.getMessage());}}});JBNext.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JTNumber.setText("");JTName.setText("");JTuname.setText("");JTpassword.setText("");}});}public void Select() {final JDialog fontDialog = new JDialog(this, "学生信息", false);Container con = fontDialog.getContentPane();JPanel panel1 = new JPanel();panel1.setLayout(new GridLayout(6, 2));JPanel panel2 = new JPanel();JLabel J1 = new JLabel("请输入学号:");final JTextField JT1 = new JTextField("");JLabel Jname = new JLabel("姓名:");final JTextField JTname = new JTextField("");JLabel JLmath = new JLabel("数学:");final JTextField JTmath = new JTextField();JLabel JLchinese = new JLabel("语文:");final JTextField JTchinese = new JTextField();JLabel JLeng = new JLabel("英语:");final JTextField JTeng = new JTextField(15);JLabel JLzhengzhi = new JLabel("政治:");final JTextField JTzhengzhi = new JTextField(15);JButton JB1 = new JButton("查询");JButton JB2 = new JButton("重置");JButton JB3 = new JButton("删除");JButton JB4 = new JButton("修改");panel1.add(J1);panel1.add(JT1);panel1.add(Jname);panel1.add(JTname);panel1.add(JLmath);panel1.add(JTmath);panel1.add(JLchinese);panel1.add(JTchinese);panel1.add(JLeng);panel1.add(JTeng);panel1.add(JLzhengzhi);panel1.add(JTzhengzhi);panel2.add(JB1);panel2.add(JB2);panel2.add(JB3);panel2.add(JB4);con.setLayout(new GridLayout(2, 1));con.add(panel1);con.add(panel2);fontDialog.setSize(400, 340);fontDialog.setLocation(200, 200);fontDialog.setResizable(true);fontDialog.setVisible(true);JB1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");} catch (ClassNotFoundException ce) {}try {Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager", "sa", "123456");Statement stm = con.createStatement();ResultSet rs = stm.executeQuery("select * from info where 学号=  '" + JT1.getText() + "'");if (rs.next()) {JTname.setText(rs.getString("姓名"));JTmath.setText(rs.getString("数学"));JTchinese.setText(rs.getString("语文"));JTeng.setText(rs.getString("英语"));JTzhengzhi.setText(rs.getString("政治"));} else {JOptionPane.showMessageDialog(null, "不存在该记录!");}} catch (SQLException se) {JOptionPane.showMessageDialog(null, se.getMessage());}}});JB2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {JT1.setText(null);JTmath.setText("");JTchinese.setText("");JTeng.setText("");JTzhengzhi.setText("");JT1.requestFocus();}});JB3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager", "sa", "123456");Statement stmt = con.createStatement();int a = stmt.executeUpdate("delete from info where 学号='" + JT1.getText() + "' ");if (a == 1) {JOptionPane.showMessageDialog(null, "删除成功!");} else {JOptionPane.showMessageDialog(null, "删除失败!");}JTmath.setText("");JTchinese.setText("");JTeng.setText("");JTzhengzhi.setText("");con.close();} catch (SQLException ee) {}}});JB4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {try {Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=StudentManager", "sa", "123456");Statement stmt = con.createStatement();int a =    stmt.executeUpdate("Update info set 数学='"+JTmath.getText()+"'," +"语文='"+JTchinese.getText()+"',"+"英语='"+JTeng.getText()+"',"+"政治="+JTzhengzhi.getText()+"where 学号='"+JT1.getText()+"'");stmt = con.createStatement();//System.out.println("chenggong");if (a == 1) {JOptionPane.showMessageDialog(null, "修改成功");} else {JOptionPane.showMessageDialog(null, "修改失败");}JTmath.setText("");JTchinese.setText("");JTeng.setText("");JTzhengzhi.setText("");con.close();} catch (SQLException se) {}}});}@Overridepublic void actionPerformed(ActionEvent e) {// TODO Auto-generated method stubif (e.getSource() == itemAdd) {Add();} else if (e.getSource() == item1) {new allstudent();} else {Select();}}public static void main(String[] args) {//       TODO Auto-generated method stubnew Teacher();}
}

Java课程设计源码——学生信息管理系统 SQL相关推荐

  1. Java课程设计报告--绩效考核信息管理系统

     Java课程设计报告 题目      绩效考核信息管理系统    学生姓名         学    号                   院    系        年级专业计算机科学与技术 班 ...

  2. python学生信息管理系统课程设计报告_学生信息管理系统课程设计报告

    一. 引言(简要说明设计题目的目的.意义.内容.主要任务等) 1 实验目的 在全面掌握< C 语言程序设计>课程的知识点的前提下,培养了我们分析实际问题的能力,并能够自己编写程序 实现对实 ...

  3. 网上教学系统mysql课程设计_基于学生信息管理系统的数据库系统课程设计(MySQL)...

    题目:学生信息管理系统 1 系统需求分析 学校每年都有新生入学.老生毕业,还有其他各种人事变动.如何有效地管理这些学生 的信息,帮助学校和老师掌握学生的情况,这就是学生信息管理系统需要完成的功能. 1 ...

  4. java桌面通讯录源码_TONGXUNLU JAVA通讯录源码 JAVA课程设计源码 讯友桌面通讯录 通讯录管理 - 下载 - 搜珍网...

    讯友桌面通讯录/.classpath 讯友桌面通讯录/.project 讯友桌面通讯录/.settings/org.eclipse.jdt.core.prefs 讯友桌面通讯录/bin/com/zzk ...

  5. java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw

    java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw java毕业生设计眼科医疗室信息管理系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B ...

  6. java计算机毕业设计基于Ssm学生信息管理系统源码+数据库+系统+lw文档+mybatis+运行部署

    java计算机毕业设计基于Ssm学生信息管理系统源码+数据库+系统+lw文档+mybatis+运行部署 java计算机毕业设计基于Ssm学生信息管理系统源码+数据库+系统+lw文档+mybatis+运 ...

  7. C语言源码做的职工工资管理系统课程设计(源码+课程设计报告)

    一.课程设计的目的: C语言课程设计是计算机科学与技术专业重要的实践性教学环节之一,本次设计结合实际应用的要求,使课程设计既覆盖C语言程序设计的知识点,又接近工程实际需要.本次设计的目的是通过课程设计 ...

  8. html课堂考勤系统源码,考勤管理系统课程设计源码

    考勤管理系统课程设计源码 源码描述: 主体分两个大块 员工信息 个人信息查询,员工信息修改,修改密码,添加用户,删除用户 企业管理 考勤登记,基本工资设置,员工考勤,自动生成变动工资表,自动生成福利费 ...

  9. C语言源码做的运动会管理系统课程设计(源码+课程设计报告)

    一.课程设计的目的: C语言程序设计课程设计是计算机科学与技术专业重要的实践性教学环节之一,本次设计结合实际应用的要求,使课程设计既覆盖C语言的知识点,又接近工程实际需要.目的是通过课程设计的综合训练 ...

最新文章

  1. Ant Design 3.0 使用案例
  2. 台式计算机防盗锁怎么安装,怎样拆装防盗门锁?防盗门锁怎么进行正确安装?...
  3. Source Insight checking for modified files 卡顿(Reload externally modified files automatically取消)(未解决)
  4. 画图分析ehcach的缓存流程图
  5. SQL Server系列
  6. jQuery学习: 实现select multiple左右添加和删除功能
  7. android开发学习---开发一个简易的短信发送器
  8. tensorflow入门(一)波士顿房价数据集
  9. [基础]tfcenter搭建个人服务器
  10. PHP显示了验证码但不能登陆,thinkphp5 登陆后台验证码无法显示
  11. 用计算机按余弦,知道余弦的值怎么用计算器求度数
  12. 关键词热度分析工具_不懂亚马逊关键词分析怎么办?10款超好用的亚马逊运营必备关键词研究分析工具,建议收藏!...
  13. 聆听音乐-推荐好听的歌曲
  14. php短视频转码,YYC松鼠短视频系统V2.0版本发布,亮点新增转码加水印功能
  15. 人工蜂群算法(Artificial Bee Colony, ABC)MATALAB代码详细解析
  16. 浏览器配置异常_浏览器配置错误 设置为可信站点或调整当前浏览器模式
  17. b区计算机211学校排名,b区211大学名单排名
  18. linux设置网口ip地址,linux网口设置ip地址
  19. 关于校园霸凌,刚刚发生(第四天的进展)
  20. 【超图+CESIUM】【基础API使用示例】41、超图|CESIUM - 特效-雪景设置

热门文章

  1. 面向对象:类与对象的近一步研究
  2. 计算机卡牌培养游戏,2020好玩的放置卡牌养成类游戏推荐 卡牌放置 轻松养成
  3. 二进制的加减乘除法全了看一下叭
  4. 【破解教程】PE文件格式详解(上)
  5. 和时间赛跑之优化高斯金字塔建立的计算过程
  6. simple foc 移植KEIL驱动双路电机
  7. 站在供应链全局视角来了解服装行业
  8. MaxDos网络克隆ip地址的设置
  9. oracle+查询spid,根据sql_id查找 spid
  10. vscode 全局搜索时屏蔽node_modules和dist 目录