MySql数据库课程设计(学生管理系统)
更新时间:2023-07-31 22:01:01 阅读量: 教育文库 文档下载
- MySQL数据库课程设计推荐度:
- 相关推荐
Window是主界面
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Window {
public static void main(String[] args){
JFrame jframe = new JFrame("学生管理系统") ; //window
Dimension d = new Dimension(400,300);
Point p = new Point (250,350);
jframe.setSize(d);
jframe.setLocation(p);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setVisible(true);
JButton button1 = new JButton("添加");
JButton button2 = new JButton("修改");
JButton button3 = new JButton("查询");
JButton button4 = new JButton("删除");
JButton button5 = new JButton("浏览");
FlowLayout flow = new FlowLayout(FlowLayout.LEFT,10,10);
JPanel panel = new JPanel(flow);
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
panel.add(button5);
jframe.add(panel);
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Add add = new Add();
}
});
button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Change change = new Change();
}
});
button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Ask ask = new Ask();
}
});
button4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Delete delete = new Delete();
}
});
button5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Look look = new Look();
}
});
}
}
Add是添加
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.mysql.jdbc.Driver;
import First.Window;
public class Add extends JFrame {
private static final long serialVersionUID = -1928970409928880648L;
JLabel jlnumber = new JLabel("学号:");
JLabel jlname = new JLabel("姓名:");
JLabel jlsex = new JLabel("性别:");
JLabel jlbirthday = new JLabel("出生日期:");
JLabel jldepartment = new JLabel("学院:");
JTextField jtnumber = new JTextField("",20);
JTextField jtname = new JTextField("",20);
JTextField jtsex = new JTextField("",20);
JTextField jtbirthday = new JTextField("",20);
JTextField jtdepartment = new JTextField("",20);
JButton buttonadd = new JButton("添加");
JButton buttonreturn = new JButton("返回");
public Add() {
JPanel jpnumber = new JPanel();
JPanel jpname = new JPanel();
JPanel jpsex = new JPanel();
JPanel jpbirthday = new JPanel();
JPanel jpdepartment = new JPanel();
JPanel jpforbutton = new JPanel(new GridLayout(1,1));
jpnumber.add(jlnumber);
jpnumber.add(jtnumber);
jpname.add(jlname);
jpname.add(jtname);
jpsex.add(jlsex);
jpsex.add(jtsex);
jpbirthday.add(jlbirthday);
jpbirthday.add(jtbirthday);
jpdepartment.add(jldepartment);
jpdepartment.add(jtdepartment);
jpforbutton.add(buttonadd);
jpforbutton.add(buttonreturn);
buttonadd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
//Add
Connection conn = null;
Statement stat = null;
PreparedStatement ps=null;
String sql = "INSERT INTO student(number,name,sex,birthday,department) "
+ "values(?,?,?,?,?)";
try{
Class.forName("Driver");
System.out.println("JBDC 加载成功!");
}catch(Exception a){
System.out.println("JBDC 狗带!");
a.printStackTrace();
}
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
ps=conn.prepareStatement(sql);
ps.setString(1,jtnumber.getText());
ps.setString(2,jtname.getText());
ps.setString(3,jtsex.getText());
ps.setString(4,jtbirthday.getText());
ps.setString(5,jtdepartment.getText());
ps.executeUpdate();
//System.out.println("MySQL 连接成功!");
//stat = conn.createStatement();
//stat.executeUpdate(sql);
//System.out.println("插入数据成功!");
}catch (SQLException b){
b.printStackTrace();
}finally{
try{
conn.close();
System.out.println("MySQL 关闭成功");
}catch (SQLException c){
System.out.println("MySQL 关闭失败 ");
c.printStackTrace();
}
}
}}
);
buttonreturn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Window window = new Window();
}
});
this.setTitle("添加学生信息");
this.setLayout(new GridLayout(9,1));
this.add(jpnumber);
this.add(jpname);
this.add(jpsex);
this.add(jpbirthday);
this.add(jpdepartment);
this.add(jpforbutton);
this.setLocation(400,300);
this.setSize(350,300);
this.setVisible(true);
}
}
Ask是查询
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import First.Window;
public class Ask extends JFrame {
private static final long serialVersionUID = -1928970409928880648L;
JLabel jlnumber = new JLabel("学号:");
JLabel jlname = new JLabel("姓名:");
JLabel jlsex = new JLabel("性别:");
JLabel jlbirthday = new JLabel("出生日期:");
JLabel jldepartment = new JLabel("学院:");
JTextField jtnumber = new JTextField("",20);
JLabel jname = new JLabel();
JLabel jsex = new JLabel();
JLabel jbirthday = new JLabel();
JLabel jdepartment = new JLabel();
JButton buttonask = new JButton("查询");
JButton buttonreturn = new JButton("返回");
public Ask() {
JPanel jpnumber = new JPanel();
JPanel jpname = new JPanel();
JPanel jpsex = new JPanel();
JPanel jpbirthday = new JPanel();
JPanel jpdepartment = new JPanel();
JPanel jpforbutton = new JPanel(new GridLayout(1,1));
jpnumber.add(jlnumber);
jpnumber.add(jtnumber);
jpname.add(jlname);
jpname.add(jname);
jpsex.add(jlsex);
jpsex.add(jsex);
jpbirthday.add(jlbirthday);
jpbirthday.add(jbirthday);
jpdepartment.add(jldepartment);
jpdepartment.add(jdepartment);
jpforbutton.add(buttonask);
jpforbutton.add(buttonreturn);
buttonask.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Connection conn = null;
ResultSet res = null;
Statement stat = null;
String sql = "SELECT number,name,sex,birthday,department FROM student;";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception d){
System.out.println("jdbc fall");
d.printStackTrace();
}
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
stat=conn.createStatement();
res=stat.executeQuery(sql);
while (res.next())
{
if (res.getString(1).equals(jtnumber.getText()))
{
jname.setText(res.getString(2));
jsex.setText(res.getString(3));
jbirthday.setText(res.getString(4));
jdepartment.setText(res.getString(5));
break;
}
}
}catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
try{
conn.close();
}catch(SQLException ar){
ar.printStackTrace();
}
}}}
);
buttonreturn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Window window = new Window();
}
});
this.setTitle("查询学生信息");
this.setLayout(new GridLayout(9,1));
this.add(jpnumber);
this.add(jpname);
this.add(jpsex);
this.add(jpbirthday);
this.add(jpdepartment);
this.add(jpforbutton);
this.setLocation(400,300);
this.setSize(350,300);
this.setVisible(true);
}
}
Change是修改
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import First.Window;
public class Change extends JFrame {
private static final long serialVersionUID = -1928970409928880648L;
JLabel jlnumber = new JLabel("学号:");
JLabel jlname = new JLabel("姓名:");
JLabel jlsex = new JLabel("性别:");
JLabel jlbirthday = new JLabel("出生日期:");
JLabel jldepartment = new JLabel("学院:");
JTextField jtnumber = new JTextField("",20);
JTextField jtname = new JTextField("",20);
JTextField jtsex = new JTextField("",20);
JTextField jtbirthday = new JTextField("",20);
JTextField jtdepartment = new JTextField("",20);
JButton buttonchange = new JButton("修改");
JButton buttonreturn = new JButton("返回");
public Change() {
JPanel jpnumber = new JPanel();
JPanel jpname = new JPanel();
JPanel jpsex = new JPanel();
JPanel jpbirthday = new JPanel();
JPanel jpdepartment = new JPanel();
JPanel jpforbutton = new JPanel(new GridLayout(1,1));
jpnumber.add(jlnumber);
jpnumber.add(jtnumber);
jpname.add(jlname);
jpname.add(jtname);
jpsex.add(jlsex);
jpsex.add(jtsex);
jpbirthday.add(jlbirthday);
jpbirthday.add(jtbirthday);
jpdepartment.add(jldepartment);
jpdepartment.add(jtdepartment);
jpforbutton.add(buttonchange);
jpforbutton.add(buttonreturn);
buttonchange.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String number = jtnumber.getText();
String name = jtname.getText();
String sex = jtsex.getText();
String birthday = jtbirthday.getText();
String department = jtdepartment.getText();
Connection conn = null;
ResultSet res = null;
Statement stat = null;
String sql = "SELECT number,name,sex,birthday,department FROM student;";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception d){
System.out.println("jdbc fall");
d.printStackTrace();
}
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
stat=conn.createStatement();
res=stat.executeQuery(sql);
while (res.next())
{
//change
if (res.getString(1).equals(jtnumber.getText()))
{
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception d){
System.out.println("jdbc fall");
d.printStackTrace();
}
String sql2="UPDATE student SET name='"+name+"' WHERE number='"+jtnumber.getText()+"'";
String sql3="UPDATE student SET sex='"+sex+"' WHERE number='"+jtnumber.getText()+"'";
String sql4="UPDATE student SET birthday='"+birthday+"' WHERE number='"+jtnumber.getText()+"'";
String sql5="UPDATE student SET department='"+department+"' WHERE number='"+jtnumber.getText()+"'";
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
stat=conn.createStatement();
stat.executeUpdate(sql2);
stat.executeUpdate(sql3);
stat.executeUpdate(sql4);
stat.executeUpdate(sql5);
} catch (SQLException g) {
// TODO Auto-generated catch block
g.printStackTrace();
}try{
stat.close();
conn.close();
}catch(SQLException ar){
ar.printStackTrace();
}
break;
}
//change end
}
}catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
finally{
try{
conn.close();
}catch(SQLException ar){
ar.printStackTrace();
}
}
}
});
buttonreturn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Window window = new Window();
}
});
this.setTitle("修改学生信息");
this.setLayout(new GridLayout(9,1));
this.add(jpnumber);
this.add(jpname);
this.add(jpsex);
this.add(jpbirthday);
this.add(jpdepartment);
this.add(jpforbutton);
this.setLocation(400,300);
this.setSize(350,300);
this.setVisible(true);
}
}
Delete是删除
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import First.Window;
public class Delete extends JFrame {
private static final long serialVersionUID = -1928970409928880648L;
JLabel jlnumber = new JLabel("学号:");
JTextField jtnumber = new JTextField("",20);
JButton buttondelete = new JButton("删除");
JButton buttonreturn = new JButton("返回");
public Delete() {
JPanel jpnumber = new JPanel();
JPanel jpforbutton = new JPanel(new GridLayout(1,1));
jpnumber.add(jlnumber);
jpnumber.add(jtnumber);
jpforbutton.add(buttondelete);
jpforbutton.add(buttonreturn);
buttondelete.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String number = jtnumber.getText();
Connection conn = null;
ResultSet res = null;
Statement stat = null;
String sql = "DELETE FROM student WHERE number='"+number+"'";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(Exception a){
a.printStackTrace();
}
try{
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
stat = conn.createStatement();
stat.executeUpdate(sql);
}catch(SQLException h){
h.printStackTrace();
}finally{
try{
conn.close();
System.out.println("close success!");
}catch(SQLException j){
System.out.println("close go die!");
j.printStackTrace();
}
}
}
});
buttonreturn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Window window = new Window();
}
});
this.setTitle("删除学生信息");
this.setLayout(new GridLayout(9,1));
this.add(jpnumber);
this.add(jpforbutton);
this.setLocation(400,300);
this.setSize(350,300);
this.setVisible(true);
}
}
Look是浏览
package First;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import First.Window;
public class Look extends JFrame {
private static final long serialVersionUID = -1928970409928880648L;
Connection conn = null;
PreparedStatement ps = null;
ResultSet res = null;
//JButton buttonlook = new JButton("浏览");
//JButton buttonreturn = new JButton("返回");
JTable jtable;
JScrollPane jscrollpane = new JScrollPane();
Vector columnNames = null;
Vector rowData = null;
public Look() {
JPanel jpforbutton = new JPanel(new GridLayout(1,1));
columnNames = new Vector();
columnNames.add("学号");
columnNames.add("姓名");
columnNames.add("性别");
columnNames.add("出生日期");
columnNames.add("学院");
rowData = new Vector();
//jpforbutton.add(buttonlook);
//jpforbutton.add(buttonreturn);
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/javaStu","root","123");
ps = conn.prepareStatement("SELECT * FROM student");
res = ps.executeQuery();
while (res.next())
{
Vector hang = new Vector();
hang.add(res.getString(1));
hang.add(res.getString(2));
hang.add(res.getString(3));
hang.add(res.getString(4));
hang.add(res.getString(5));
rowData.add(hang);
}
System.out.println("load ok!");
}catch (Exception q){
q.printStackTrace();
System.out.println("go die");
}finally{
try{
res.close();
ps.close();
conn.close();
System.out.println("close ok");
}catch (SQLException o){
o.printStackTrace();
System.out.println("go die 2");
}
}
jtable = new JTable(rowData,columnNames);
jscrollpane = new JScrollPane(jtable);
this.add(jscrollpane);
this.setTitle("浏览学生信息");
this.setLayout(new GridLayout(2,5));
this.add(jpforbutton);
this.setLocation(300,300);
this.setSize(500,300);
this.setVisible(true);
this.setResizable(false);
}
}
————————————————
版权声明:本文为CSDN博主「Hyouka1203」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_34472846/article/details/51097965
正在阅读:
MySql数据库课程设计(学生管理系统)07-31
固定资产加速折旧(扣除)明细表(附表2)及填报说明04-21
税务会计练习题103-16
《现代交换技术》期末试题库10-16
田统期中-答案05-12
专职辅导员招聘笔试试题03-05
火电厂典型危险点分析预控措施04-12
2022年中小学五项管理工作方案五项管理实施方案范本(完整版)07-31
理论力学竞赛练习题12-03
电路原理重点十四03-05
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 管理系统
- 课程
- 数据库
- 学生
- 设计
- MySql
- 在党史学习教育专题读书班开班仪式上的动员讲话
- XX公司上半年党史学习教育工作总结
- xx县xx村乡村振兴规划方案
- xx党支部党史学习教育开展情况总结
- 村务监督委员会监督内容和程序
- 岗位调动申请书范文
- XX县委向市委巡回指导组汇报党史学习教育开展情况范文(存在问题及下一步打算)
- 个人申请书格式范文
- 保密协议(通用版)
- 在党史学习教育专题读书班结束时的总结讲话
- 2022年中小学校学生学党史学习教育活动工作总结主持词汇编
- “全面预算管理”案例
- 签订合同授权委托书
- APMS全通纸笔王网上阅卷系统
- 防溺水工作实施方案
- 党的十八大以来的历史研讨发言范文(党建材料)
- 学校庆七一活动简报
- 单位党的十九大开幕式收听收看情况汇报
- 2022年第二季度入党积极分子思想汇报结合时事范文五篇
- 汉语拼音字母表完整版可A4打印