上海电力学院
期末作业:简单的学籍管理系统
课 程: Web应用程序设计
院 系: 电气工程学院
专 业: 电力系统及其自动化 学生姓名: 张富杰 学号:17103060
指导教师: 曹渝昆
2017年1月6日
1 / 30
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
目录
一、设计思路 ............................................................................................................... 3 二具体实现 ................................................................................................................... 3 三运行调试与分析 ....................................................................................................... 3 四设计体会与小结 ....................................................................................................... 8 五程序代码 ................................................................................................................... 8
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
一、设计思路
随着社会经济的发展,入学的同学越来越多,为方便对同学学籍信息的的管理,设计学籍管理软件来管理本班级同学的学籍信息。该软件应支持添加、删除、修改、查询功能。
查询方式主要是支持学号查询,例如:输入“1”,则显示该学生的信息。 运用流式、卡片、整体布局方式对系统的主界面和各功能界面进行设计; 通过连接数据库的方式来实现对数据的存储;各功能实现时访问数据库,并对数据信息进行读取,运用Java语句对其进行输出,学号查询时显示在文本框中;系统提示功能用来提醒用户的错误操作和输入时的错误信息,提醒用户进行改正。
二具体实现
1. 向班级里插入一个学生,但必须是插在已经建立的班级里。 2. 输入学生信息,建立一个班级。 3. 修改一个学生的所有资料。
4. 删除某班的一个学生及其所有资料。 5. 删除一个班级。 6.根据学生姓名查找某个学生信息。
每种功能通过一个类来实现:类分分为主类、查询类、修改类、添加类、增加类。主类各功能界面的连接;精确查询类(SearchStudent)实现根据学生姓名查找某个学生信息;修改类(MdifyStudent)实现修改一个学生的所有资料;添加类(AddStudent)实现向班级里插入一个学生,但必须是插在已经建立的班级里。;删除类(DeleteStudent)实现删除某班的一个学生及其所有资料。;删除类(DeleteClass)实现删除一个班级;建立类(BuiltClass)实现输入学生信息建立一个班级。
三运行调试与分析
系统的详细设计代码请查阅附带的代码。以下仅对各个界面进行截图展示:
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
图1:管理界面
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
图2:添加学生到指定的班级界面
图3:删除一个学生信息界面
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
图4:修改一个学生信息界面
图5:查询某个学生信息界面
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
图6删除一个班级界面
图7:输入一个学生建立一个班级界面
运行JAVA程序中的StudentManager文件,显示系统的主界面,如图1所示,主界面有进入其他子功能的按钮,选择相应的按钮便可进入相应的功能。添加学生到指定班级功能如图2所示,根据提示输入要添加的信息,点击确定,将弹出
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
提示框,确认是否添加。
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
输入一个学生建立一个班级功能如图7所示,根据提示输入要添加的信息,点击确定,将弹出提示框,确认是否建立。删除一个班级信息功能如图6所示,根据提示输入班级号,点击删除。删除一个学生信息功能如图3所示,根据提示输入学号,点击删除。修改一个学生信息功能如图4所示,首先输入要修改的人姓名,点击开始修改,在下面的文本框现实当前数据库内所存该人的信息,同时录入修改键变化为可点击,在文本框内输入要修改的学号,点击录入修改,系统将新信息录如数据库。点击查询某个学生信息按钮,将弹出查询对话框, 输入姓名便可以精确查询到此人的所有学籍信息。查询如图5所示,将显示数据库中所存的所有号码信息。
四设计体会与小结
期末大作业的课设,自己通过查找资料、复习课本、编程调试,写实验报告等环节,进一步掌握了以前学到的知识,并且还对GUI组键的应用有了更深入的认识与掌握,另外还学到了一些新东西,比如JAVA 的SWING、AWT包,以前是没有接触过的,可是通过这次课程设计使得我们对这个包更了解。通过与数据库的连接掌握了Java与数据库的连接技术。
通过实践的学习,我认到学好计算机要重视实践操作,不仅仅是学习java语言,还是其它的语言,以及其它的计算机方面的知识都要重在实践,所以后在学习过程中,我会更加注视实践操作,使自己便好地学好计算机。
五程序代码
package simplebighomework; import javax.swing.*;
import java.awt.*; import java.awt.event.*; import java.sql.*;
public class StudentManager extends JFrame implements ActionListener { //继承JFrame类
JMenuBar jmb; //菜单栏 JMenu Message; //菜单
JMenuItem Item1,Item2,Item3,Item4,Item5,Item6; //菜单项 public StudentManager(String s) { //构造函数 StudentManage //添加按键
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
jmb = new JMenuBar();
Message = new JMenu(\"学生信息\");
Item1 = new JMenuItem(\"增加学生信息到指定班级\"); //菜单名 Item2 = new JMenuItem(\"删除一个学生学籍信息\"); Item3 = new JMenuItem(\"修改一个学生信息\"); Item4 = new JMenuItem(\"查询某个学生信息\"); Item5 = new JMenuItem(\"删除一个班级信息\"); Item6 = new JMenuItem(\"输入一个学生建立一个班级\");
Message.add(Item1); Message.add(Item2); Message.add(Item3); Message.add(Item4); Message.add(Item5); Message.add(Item6); jmb.add(Message);
Item1.addActionListener(this); Item2.addActionListener(this); Item3.addActionListener(this); Item4.addActionListener(this); Item5.addActionListener(this); Item6.addActionListener(this);
setTitle(s); //设置窗口标题 setBounds(500,300,500,500); //窗口的位置 setVisible(true); //组件可见 setJMenuBar(jmb);
//菜单栏
validate(); //再次布置容器及其组件
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置隐藏,关
闭,放大窗口
public void actionPerformed(ActionEvent e){ //ActionEvent包含一个 if (e.getSource() == Item1) { //e.getSource() == Item2)
事件,该事件为执行动作事件 点击按钮等
返回的当前动作所指向的对象,包含对象的所有信息。
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
}
AddStudent ad = new AddStudent();
} else if (e.getSource() == Item2) { //通过获取事件源, }
DeleteStudent ds = new DeleteStudent(); ModifyStudent ms = new ModifyStudent(); SearchStudent ss = new SearchStudent(); DeleteClass dc = new DeleteClass(); BuiltClass bc = new BuiltClass();
获取相应的对象
} else if (e.getSource() == Item3) { } else if (e.getSource() == Item4) { } else if (e.getSource() == Item5) { } else if (e.getSource() == Item6) {
public static void main(String[] args) { }
StudentManager stu=new StudentManager(\"学生管理系统\");
package simplebighomework; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*;
public class AddStudent extends JFrame implements ActionListener {//继承java的窗口体类
JLabel JL = new JLabel(\"添加学生到指定班级\ JLabel JLNumber = new JLabel(\"学号:\"); //显示输入学号 JTextField JTNumber = new JTextField(); //创建文本框 JLabel JLName = new JLabel(\"姓名:\"); JTextField JTName = new JTextField();
JLabel JLClass = new JLabel(\"班级:\"); ButtonGroup BG = new ButtonGroup();
JRadioButton JRB1 = new JRadioButton(\"一班\"); JRadioButton JRB2 = new JRadioButton(\"二班\");
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
JButton JBAdd = new JButton(\"添加\"); //创建按钮 JButton JBExit = new JButton(\"退出\"); public AddStudent() { this.setTitle(\"添加学生到指定班级\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLNumber.setBounds(140, 80, 100, 20); //x this.add(JLNumber);
JTNumber.setBounds(180, 80, 80, 20); this.add(JTNumber);
JLName.setBounds(140, 120, 60, 20); this.add(JLName);
JTName.setBounds(180, 120, 80, 20); this.add(JTName);
JLClass.setBounds(140, 160, 100, 20); this.add(JLClass);
JRB1.setBounds(180, 160, 60, 20); JRB2.setBounds(240, 160, 60, 20); this.add(JRB1); this.add(JRB2); BG.add(JRB1); BG.add(JRB2);
JBAdd.setBounds(120, 220, 60, 20); this.add(JBAdd);
JBAdd.addActionListener(this);
JBExit.setBounds(200, 220, 60, 20);
轴和y轴,宽高
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
效
}
this.add(JBExit);
JBExit.addActionListener(this);
this.setBounds(500, 300, 500, 400); //添加窗口的位置 this.setVisible(true);
public void actionPerformed(ActionEvent e) { // 监听接口
if (e.getSource() == JBAdd) { //点击建立的时候生
String snumber = JTNumber.getText(); //获取文本框中的String sname = JTName.getText(); String sclass = \"一班\";
if (JRB1.isSelected()) //单选按钮
sclass = \"一班\"; sclass = \"二班\"; else
信息
Connection con; //声明Connection对象
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\"); //1.getConnection()方法,连接MySQL数据库!!
//2.创建statement类对象,用来执行SQL语句!! id='\"+snumber+\"'\"; //要执行的SQL语句
ResultSet
rs
=
//3.ResultSet类,用来存放获取的结果集!!
Statement statement = con.createStatement();
String sql = \"select * from student where
statement.executeQuery(sql);
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
} }
if (rs.next()) }
catch (Exception ee) { //捕获异常 }
JOptionPane.showMessageDialog(null, \"该号已经存在\"); else { }
sql = \"insert into student values('\" + snumber +
int i = statement.executeUpdate(sql);
//提示
\"','\"+ sname + \"','\" + sclass +\"')\"; //执行SQL语句,把返回值赋给i
if (i > 0)
JOptionPane.showMessageDialog(null, \"建立成功
\"); //提示成功
else
JOptionPane.showMessageDialog(null, \"添加失败
\"); //提示失败
if (e.getSource() == JBExit) { //退出按钮监视 }
setVisible(false);
public static void main(String[] args) { }
new BuiltClass();
package simplebighomework; import javax.swing.*;
import java.awt.*; import java.awt.event.*;
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
import java.sql.*;
public class BuiltClass extends JFrame implements ActionListener {
JLabel JL = new JLabel(\"输入一个学生建立一个班级\JLabel JLNumber = new JLabel(\"学号:\"); //显示输入学号 JTextField JTNumber = new JTextField(); //创建文本框 JLabel JLName = new JLabel(\"姓名:\"); JTextField JTName = new JTextField(); JLabel JLClass = new JLabel(\"班级:\"); JTextField JTClass = new JTextField();
JButton JBAdd = new JButton(\"建立\"); //创建按钮 JButton JBExit = new JButton(\"退出\"); //什么意思 public BuiltClass() {
this.setTitle(\"输入一个学生建立一个班级\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLNumber.setBounds(140, 80, 100, 20); //x轴和y轴,宽高 this.add(JLNumber);
JTNumber.setBounds(180, 80, 80, 20); this.add(JTNumber);
JLName.setBounds(140, 120, 60, 20); this.add(JLName);
JTName.setBounds(180, 120, 80, 20); this.add(JTName);
JLClass.setBounds(140, 160, 100, 20); this.add(JLClass);
JTClass.setBounds(180, 160, 80, 20); this.add(JTClass);
JBAdd.setBounds(120, 220, 60, 20); this.add(JBAdd);
//什么意思
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
效
}
JBAdd.addActionListener(this); JBExit.setBounds(200, 220, 60, 20); this.add(JBExit);
JBExit.addActionListener(this); this.setBounds(500, 300, 500, 400); this.setVisible(true);
public void actionPerformed(ActionEvent e) { //什么意思? 监
if (e.getSource() == JBAdd) { //点击建立的时候生
String snumber = JTNumber.getText(); //获取文本框中的String sname = JTName.getText(); String sclass = JTClass.getText();
Connection con; //声明Connection对象
听接口
信息
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\"); //1.getConnection()方法,连接MySQL数据库!!
Statement statement = con.createStatement();
String sql = \"select * from student where
ResultSet rs = statement.executeQuery(sql);
//2.创建statement类对象,用来执行SQL语句!! id='\"+snumber+\"'\";
//3.ResultSet类,用来存放获取的结果集!!
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
} }
if (rs.next()) }
catch (Exception ee) { //什么意思? }
JOptionPane.showMessageDialog(null, \"该号已经存在\"); else { }
sql = \"insert into student values('\" + snumber +
int i = statement.executeUpdate(sql);
//提示
\"','\"+ sname + \"','\" + sclass +\"')\"; //执行SQL语句,把返回值赋给i
if (i > 0)
JOptionPane.showMessageDialog(null, \"建立成功
\"); //提示成功
else
JOptionPane.showMessageDialog(null, \"添加失败
\"); //提示失败
if (e.getSource() == JBExit) { //什么意思? }
setVisible(false);
public static void main(String[] args) { }
new BuiltClass();
package simplebighomework;
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
import javax.swing.*;
import java.awt.*; import java.awt.event.*; import java.sql.*;
public class DeleteClass extends JFrame implements ActionListener {
JLabel JL = new JLabel(\"删除一个班级信息\ JLabel JLClass = new JLabel(\"班级:\"); //显示班级窗口 JTextField JTClass = new JTextField(); //输入班级的窗口 JButton JBDel = new JButton(\"删除\"); JButton JBExit = new JButton(\"退出\");
public DeleteClass() { }
public void actionPerformed(ActionEvent e) //执行操作
this.setTitle(\"删除一个班级信息\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLClass.setBounds(140, 80, 60, 20); this.add(JLClass);
JTClass.setBounds(180, 80, 80, 20); this.add(JTClass);
JBDel.setBounds(120, 120, 60, 20); this.add(JBDel);
JBDel.addActionListener(this);
JBExit.setBounds(200, 120, 60, 20); this.add(JBExit);
JBExit.addActionListener(this); this.setBounds(500, 300, 500, 400); this.setVisible(true);
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
{
if (e.getSource() == JBDel) {
String sclass = JTClass.getText(); //获取文本中输入
Connection con; //声明Connection对象
的班级
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\"); //1.getConnection()方法,连接MySQL数据库!!
//2.创建statement类对象,用来执行SQL语句!! class='\"+sclass+\"'\";
Statement statement = con.createStatement();
String sql = \"select * from student where ResultSet rs = statement.executeQuery(sql);
if (rs.next()) { }
sql = \"delete from student where class='\" + sclass + int n = statement.executeUpdate(sql); if (n > 0)
JOptionPane.showMessageDialog(null, \"删除成功\"); JOptionPane.showMessageDialog(null, \"删除失败\"); else
//3.ResultSet类,用来存放获取的结果集!!
\"'\";
} else {
JOptionPane.showMessageDialog(null, \"不存在该班级\");
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
}
}
}
catch (Exception er) { }
if (e.getSource() == JBExit) { }
setVisible(false);
public static void main(String[] args) { }
new DeleteClass();
package simplebighomework; import javax.swing.*;
import java.awt.*; import java.awt.event.*; import java.sql.*;
public class DeleteStudent extends JFrame implements ActionListener {
JLabel JL = new JLabel(\"删除一个学生信息\ JLabel JLNumber = new JLabel(\"学号:\"); //显示输入“学号” JTextField JTNumber = new JTextField(); // 输入学号的文本框 JLabel JLClass = new JLabel(\"班级:\"); //显示输入“班级” JTextField JTClass = new JTextField(); // 输入班级的文本框 JLabel JLName = new JLabel(\"姓名:\"); //显示输入“姓名” JTextField JTName = new JTextField(); // 输入姓名的文本框 JButton JBDel = new JButton(\"删除\"); //删除键 JButton JBExit = new JButton(\"退出\"); //退出键
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
public DeleteStudent() {
this.setTitle(\"删除一个学生信息\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLNumber.setBounds(140, 80, 100, 20); //x轴和y轴,宽高 this.add(JLNumber);
JTNumber.setBounds(180, 80, 80, 20); this.add(JTNumber);
JLName.setBounds(140, 120, 80, 20); //x轴和y轴,宽高 this.add(JLName);
JTName.setBounds(180, 120, 80, 20); this.add(JTName);
JLClass.setBounds(140, 160, 80, 20); //x轴和y轴,宽高 this.add(JLClass);
JTClass.setBounds(180, 160, 80, 20); this.add(JTClass);
JBDel.setBounds(120, 200, 60, 20); this.add(JBDel);
JBDel.addActionListener(this); JBExit.setBounds(200, 200, 60, 20); this.add(JBExit);
JBExit.addActionListener(this);
this.setBounds(500, 300, 500, 400); this.setVisible(true); }
public void actionPerformed(ActionEvent e){
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
if (e.getSource() == JBDel) {
Connection con; //声明Connection对象 String snumber = JTNumber.getText(); //获取输入的学号
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\");
Statement statement = con.createStatement();
String sql = \"select * from student where
ResultSet rs = statement.executeQuery(sql);
if (rs.next()) {
sql = \"delete from student where id='\" + snumber + \"'\"; int n = statement.executeUpdate(sql); if (n > 0)
JOptionPane.showMessageDialog(null, \"删除成功\");
//2.创建statement类对象,用来执行SQL语句!! id='\"+snumber+\"'\";
//3.ResultSet类,用来存放获取的结果集!!
//执行了返回删除成功
else }
JOptionPane.showMessageDialog(null, \"不存在该学号学
JOptionPane.showMessageDialog(null, \"删除失败\");
else {
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
生\");
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
}
}
}
}
catch (Exception er) { }
if (e.getSource() == JBExit) { }
setVisible(false);
public static void main (String[] args) { }
new DeleteStudent();
package simplebighomework; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*;
public class ModifyStudent extends JFrame implements ActionListener {
JLabel JL = new JLabel(\"修改一个学生信息\ JLabel JLNumber = new JLabel(\"学号:\"); //显示学号 JTextField JTNumber = new JTextField(); //创建用于输入学号
JLabel JLName = new JLabel(\"姓名:\"); JTextField JTName = new JTextField();
JLabel JLClass = new JLabel(\"班级:\");
的文本
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
JTextField JTClass = new JTextField();
JButton JBGet = new JButton(\"修改\"); //修改按钮 JButton JBExit = new JButton(\"退出\"); public ModifyStudent() { this.setTitle(\"修改一个学生信息\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLNumber.setBounds(140, 80, 100, 20); //x this.add(JLNumber);
JTNumber.setBounds(180, 80, 80, 20); this.add(JTNumber);
JLName.setBounds(140, 120, 60, 20); this.add(JLName);
JTName.setBounds(180, 120, 80, 20); this.add(JTName);
JLClass.setBounds(140, 160, 100, 20); this.add(JLClass);
JTClass.setBounds(180, 160, 80, 20); this.add(JTClass);
JBGet.setBounds(120, 220, 60, 20); this.add(JBGet);
JBGet.addActionListener(this);
JBExit.setBounds(200, 220, 60, 20); this.add(JBExit);
JBExit.addActionListener(this);
this.setBounds(500, 300, 500, 400);
this.setVisible(true);
轴和y轴,宽高
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == JBGet) {
String snumber = JTNumber.getText(); //读取文本中输入的String sname = JTName.getText(); String sclass = JTClass.getText();
Connection con; //声明Connection对象
学号
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\"); //1.getConnection()方法,连接MySQL数据库!!
Statement statement = con.createStatement();
String sql = \"select * from student where
//根据id对数据库查询
ResultSet rs = statement.executeQuery(sql);
if (rs.next()) {
sql = \"UPDATE student SET name='\" +sname+ int
n
=
//2.创建statement类对象,用来执行SQL语句!! id='\"+snumber+\"'\";
//3.ResultSet类,用来存放获取的结果集!!
\"',class='\"+sclass+ \"'where id='\" + snumber + \"'\"; //什么意思?
if (n > 0)
JOptionPane.showMessageDialog(null, \"修改成功\"); else
statement.executeUpdate(sql);
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
}
}
}
}
JOptionPane.showMessageDialog(null, \"修改失败\");
} else {
JOptionPane.showMessageDialog(null, \"不存在该学号学
生\");
catch (Exception er) { }
if (e.getSource() == JBExit) { }
new ModifyStudent();
setVisible(false);
} public static void main(String[] args) {
package simplebighomework; import javax.swing.*;
import java.awt.*; import java.awt.event.*; import java.sql.*;
public class SearchStudent extends JFrame implements ActionListener {
JLabel JL = new JLabel(\"查询某个学生信息\ JLabel JLNumber = new JLabel(\"学号:\");
JTextField JTNumber = new JTextField(); //输入学号的文本 JLabel JLName = new JLabel(\"姓名:\"); JTextField JTName = new JTextField(); JLabel JLClass = new JLabel(\"班级:\"); JTextField JTClass = new JTextField();
JButton JBSet = new JButton(\"查询\"); //查询按钮
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
JButton JBExit = new JButton(\"退出\"); //退出按钮
public SearchStudent() { //设置窗口的大小,位置 this.setTitle(\"查询某个学生信息\"); this.setLayout(null);
JL.setBounds(100, 30, 200, 40); this.add(JL);
JLNumber.setBounds(140, 80, 80, 20); //x this.add(JLNumber);
JTNumber.setBounds(180, 80, 80, 20); this.add(JTNumber);
JLName.setBounds(140, 120, 80, 20); //x this.add(JLName);
JTName.setBounds(180, 120, 80, 20); this.add(JTName);
JLClass.setBounds(140, 160, 80, 20); //x this.add(JLClass);
JTClass.setBounds(180, 160, 80, 20); this.add(JTClass);
JBSet.setBounds(120, 200, 60, 20); this.add(JBSet);
JBSet.addActionListener(this);
JBExit.setBounds(200, 200, 60, 20); this.add(JBExit);
JBExit.addActionListener(this);
this.setBounds(500, 300, 500, 400);
轴和y轴,宽高轴和y轴,宽高 轴和y轴,宽高
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
}
this.setVisible(true);
public void actionPerformed(ActionEvent e) {
if (e.getSource() == JBSet) {
Connection con; //声明Connection对象 String sname = JTName.getText(); //获取文本中输入的学号
String driver = \"com.mysql.jdbc.Driver\"; //驱动程序名
//遍历查询结果集 try { con
=
Class.forName(driver); //加载驱动程序
DriverManager.getConnection(\"jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=utf-8&useSSL=false\2062\"); //1.getConnection()方法,连接MySQL数据库!!
Statement statement = con.createStatement();
String sql = \"select * from student where
ResultSet rs = statement.executeQuery(sql);
//2.创建statement类对象,用来执行SQL语句!! name='\"+sname+\"'\";
//3.ResultSet类,用来存放获取的结果集!! if (rs.next())
{ //查询数据,然后返回
String number = rs.getString(1); JTNumber.setText(number); String clas = rs.getString(3); JTClass.setText(clas);
int n = statement.executeUpdate(sql); if (n > 0) \");
JOptionPane.showMessageDialog(null, \"查询成功
传播优秀Word版文档 ,希望对您有帮助,可双击去除!
else \");
} else {
JOptionPane.showMessageDialog(null, \"不存在该姓名 JOptionPane.showMessageDialog(null, \"查询失败
的学生\");
} }
catch (Exception ee) { } }
if (e.getSource() == JBExit) { // setVisible(false);
}
}
public static void main(String[] args) { new SearchStudent(); }
}
-----精心整理,希望对您有所帮助!
退出按钮
因篇幅问题不能全部显示,请点此查看更多更全内容