日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

java-Mysql学生管理系统

發布時間:2023/11/30 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java-Mysql学生管理系统 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Window1//主方法
package stu_zizhu1;

import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Window1 {
public static void main(String[] args) {
JFrame jf=new JFrame("學生管理系統");

JButton b1=new JButton("添加");JButton b2=new JButton("查找");JButton b3=new JButton("修改");JButton b4=new JButton("刪除");JButton b5=new JButton("瀏覽");FlowLayout flow = new FlowLayout(FlowLayout.LEFT,10,10);JPanel jp=new JPanel(flow);jp.add(b1);jp.add(b2);jp.add(b3);jp.add(b4);jp.add(b5);jf.add(jp);jp.setBackground(Color.red);jf.setSize(500,500);jf.setLocation(500,500);jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);jf.setVisible(true);b1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Add1 a1=new Add1();}});b2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Find1 find1=new Find1();}});b3.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Modify1 modify1=new Modify1();}});b4.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Delete1 delete1=new Delete1();}});b5.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {Look1 look1=new Look1();}});}

}

package stu_zizhu1;

import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

public class Add1 extends JFrame{

//定義標簽 JLabel jlid=new JLabel("ID:"); JLabel jlname=new JLabel("Name:"); JLabel jlage=new JLabel("Age:"); JLabel jlsex=new JLabel("Sex:"); JLabel jlscore=new JLabel("Score:"); JLabel jlbirthday=new JLabel("Birthday:"); //定義文本框JTextField jfid=new JTextField("",20); JTextField jfname=new JTextField("",20); JTextField jfage=new JTextField("",20); JTextField jfsex=new JTextField("",20); JTextField jfscore=new JTextField("",20); JTextField jfbirthday=new JTextField("",20);//定義按鈕(本人再次嚴重犯錯JButton被我寫成Button 真的是頭疼) JButton tianjia=new JButton("添加"); JButton chongzhi =new JButton("重置"); JButton fanhui=new JButton("返回");public Add1() {//定義面板//jpid面板添加標簽(jlid)&&文本框(jfid)JPanel jpid=new JPanel();jpid.add(jlid);jpid.add(jfid);JPanel jpname=new JPanel();jpname.add(jlname);jpname.add(jfname);JPanel jpage=new JPanel();jpage.add(jlage);jpage.add(jfage);JPanel jpsex=new JPanel();jpsex.add(jlsex);jpsex.add(jfsex);JPanel jpscore=new JPanel();jpscore.add(jlscore);jpscore.add(jfscore);JPanel jpbirthday=new JPanel();jpbirthday.add(jlbirthday);jpbirthday.add(jfbirthday);JPanel jpbutton=new JPanel(new GridLayout(1,3));jpbutton.add(tianjia);jpbutton.add(chongzhi);jpbutton.add(fanhui);//按鈕添加監聽器tianjia.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {Connection conn=null;PreparedStatement prestat=null;Statement stat =null;String sql ="insert into student1(id,name,age,sex,score,birthday) "+"values(?,?,?,?,?,?)";//少加一個問好?try{Class.forName("Driver");System.out.println("JBDC 加載成功!");}catch(Exception a){System.out.println("JBDC 狗帶!");a.printStackTrace();}try {conn= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");prestat=(PreparedStatement) conn.prepareStatement(sql);prestat.setString(1,jfid.getText());prestat.setString(2,jfname.getText());prestat.setString(3,jfage.getText());prestat.setString(4,jfsex.getText());prestat.setString(5,jfscore.getText());prestat.setString(6,jfbirthday.getText());prestat.executeUpdate();} catch (SQLException s) {// TODO Auto-generated catch blocks.printStackTrace();}finally {try {conn.close();} catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}}}});fanhui.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {Window1 window1=new Window1();}});chongzhi.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {jfid.setText("");jfname.setText("");jfage.setText("");jfsex.setText("");jfscore.setText("");jfbirthday.setText("");}});this.setTitle("添加學生信息");this.setLayout(new GridLayout(9,1));this.add(jpid);this.add(jpname);this.add(jpage);this.add(jpsex);this.add(jpscore);this.add(jpbirthday);this.add(jpbutton);this.setLocation(400,300);this.setSize(350,300);this.setVisible(true);}

}
package stu_zizhu1;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class Find1 extends JFrame{
JLabel jlid=new JLabel("ID:");
JTextField jtfid=new JTextField("",20);

JLabel jlname=new JLabel("Name:"); JLabel jlage=new JLabel("Age:"); JLabel jlsex=new JLabel("Sex:"); JLabel jlscore=new JLabel("Score:"); JLabel jlbirthday=new JLabel("Birthday:");//JLabel jid=new JLabel(); JLabel jname=new JLabel(); JLabel jage=new JLabel(); JLabel jsex=new JLabel(); JLabel jscore=new JLabel(); JLabel jbirthday=new JLabel(); //此處按鈕一定要設置成JButton JButton query=new JButton("查詢"); JButton ret=new JButton("返回"); //此處不可有voidpublic Find1() {JPanel jpid=new JPanel();jpid.add(jlid);jpid.add(jtfid);JPanel jpname=new JPanel();jpname.add(jlname);jpname.add(jname);JPanel jpage=new JPanel();jpage.add(jlage);jpage.add(jage);JPanel jpsex=new JPanel();jpsex.add(jlsex);jpsex.add(jsex);JPanel jpscore=new JPanel();jpscore.add(jlscore);jpscore.add(jscore);JPanel jpbirthday=new JPanel();jpbirthday.add(jlbirthday);jpbirthday.add(jbirthday);JPanel button1=new JPanel(new GridLayout(1,1));button1.add(query);button1.add(ret);query.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e1) {Connection conn=null;Statement state=null;ResultSet res=null;//此處犯錯 忘記寫idString sql="select id,name,age,sex,score,birthday from student1;";try {Class.forName("com.mysql.jdbc.Driver");} catch (ClassNotFoundException e) {System.out.println("123");e.printStackTrace();}try {conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");state=(Statement) conn.createStatement();res=state.executeQuery(sql);while(res.next()) {if(res.getString(1).equals(jtfid.getText())) {jname.setText(res.getString(2));jage.setText(res.getString(3));jsex.setText(res.getString(4));jscore.setText(res.getString(5));jbirthday.setText(res.getString(6));}}} catch (SQLException e) {System.out.println("1234");e.printStackTrace();}finally {try {conn.close();} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}});ret.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {Window1 window1=new Window1();}});this.setTitle("學生查詢系統 ");this.setLayout(new GridLayout(9,1));//9組建this.add(jpid);this.add(jpname);this.add(jpage);this.add(jpsex);this.add(jpscore);this.add(jpbirthday);this.add(button1);this.setSize(300, 400);this.setLocation(300, 400);this.setVisible(true);}

}
package stu_zizhu1;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;

public class Look1 extends JFrame{
Connection conn =null;
PreparedStatement pre=null;
ResultSet res=null;

JScrollPane jps=null; Vector columnsname=null; Vector rowData=null;public Look1() {JPanel jp1=new JPanel(); jp1.setBackground(Color.gray);jp1.setSize(500, 500);JLabel jb=new JLabel("歡迎使用學生管理系統");jb.setBounds(0, 0, 50, 50);jp1.add(jb);JPanel jp=new JPanel();//JLabel jb1=new JLabel("歡迎使用學生管理系統");jp.setSize(400, 400);jp.setBackground(Color.green);//jp.add(jb1);jp.add(jp1);//定義列名columnsname=new Vector();columnsname.add("id");columnsname.add("name");columnsname.add("age");columnsname.add("sex");columnsname.add("score");columnsname.add("birthday");rowData =new Vector();try {Class.forName("com.mysql.jdbc.Driver");conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");pre=(PreparedStatement) conn.prepareStatement("select *from student1");res=pre.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));hang.add(res.getString(6));rowData.add(hang);}System.out.println("load ok!");} catch (Exception e) {System.out.println("go die");e.printStackTrace();}finally {try {res.close();pre.close();conn.close();System.out.println("close ok");} catch (SQLException e) {// TODO Auto-generated catch blocke.printStackTrace();}}JTable jtable=new JTable(rowData,columnsname);jps=new JScrollPane(jtable);this.add(jps);this.setTitle("學生瀏覽系統");this.setLayout(new GridLayout(3,4));this.add(jp);this.setSize(400, 500);this.setLocation(300,400);this.setVisible(true);this.setResizable(false);}

}
package stu_zizhu1;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.Statement;

import First.Window;

public class Modify1 extends JFrame{
//定義標簽
JLabel jlid=new JLabel("ID:");
JLabel jlname=new JLabel("Name:");
JLabel jlage=new JLabel("Age:");
JLabel jlsex=new JLabel("Sex:");
JLabel jlscore=new JLabel("Score:");
JLabel jlbirthday=new JLabel("Birthday:");
//定義文本框

JTextField jfid=new JTextField("",20); JTextField jfname=new JTextField("",20); JTextField jfage=new JTextField("",20); JTextField jfsex=new JTextField("",20); JTextField jfscore=new JTextField("",20); JTextField jfbirthday=new JTextField("",20);//定義按鈕(本人再次嚴重犯錯JButton被我寫成Button 真的是頭疼) JButton change=new JButton("修改"); JButton chongzhi =new JButton("重置"); JButton fanhui=new JButton("返回");public Modify1() {//定義面板//jpid面板添加標簽(jlid)&&文本框(jfid)JPanel jpid=new JPanel();jpid.add(jlid);jpid.add(jfid);JPanel jpname=new JPanel();jpname.add(jlname);jpname.add(jfname);JPanel jpage=new JPanel();jpage.add(jlage);jpage.add(jfage);JPanel jpsex=new JPanel();jpsex.add(jlsex);jpsex.add(jfsex);JPanel jpscore=new JPanel();jpscore.add(jlscore);jpscore.add(jfscore);JPanel jpbirthday=new JPanel();jpbirthday.add(jlbirthday);jpbirthday.add(jfbirthday);JPanel jpbutton=new JPanel(new GridLayout(1,3));jpbutton.add(change);jpbutton.add(chongzhi);jpbutton.add(fanhui);change.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent arg0) {//String id1=jfid.getText();String name1=jfname.getText();//此處犯錯String age1=jfage.getText();String sex1=jfsex.getText();String score1=jfscore.getText();String birthday1=jfbirthday.getText();Connection conn=null;Statement state=null;

// PreparedStatement prestate=null;
ResultSet res=null;

String sql="select id,name,age,sex,score,birthday from student1;";try{Class.forName("com.mysql.jdbc.Driver");}catch(Exception d){System.out.println("jdbc fall");d.printStackTrace();}try{conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");state=(Statement) conn.createStatement();res=state.executeQuery(sql);while (res.next()){//changeif (res.getString(1).equals(jfid.getText())){try{Class.forName("com.mysql.jdbc.Driver");}catch(Exception d){System.out.println("jdbc fall");d.printStackTrace();}String sql1="update student1 set name='"+name1+"'where id='"+jfid.getText()+"'";String sql2="update student1 set age='"+age1+"'where id='"+jfid.getText()+"'";String sql3="update student1 set sex='"+sex1+"'where id='"+jfid.getText()+"'";String sql4="update student1 set score='"+score1+"'where id='"+jfid.getText()+"'";String sql5="update student1 set birthday='"+birthday1+"'where id='"+jfid.getText()+"'";try {conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/yonghu?useSSL=false","root","123456");state=(Statement) conn.createStatement();state.execute(sql1);state.execute(sql2);state.execute(sql3);state.execute(sql4);state.execute(sql5);} catch (SQLException g) {// TODO Auto-generated catch blockg.printStackTrace();}try{state.close();conn.close();}catch(SQLException ar){ar.printStackTrace();}break;}//change end}}catch (SQLException e1) {// TODO Auto-generated catch blocke1.printStackTrace();}finally{try{conn.close();}catch(SQLException ar){ar.printStackTrace();}}}});fanhui.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){Window window = new Window(); } });chongzhi.addActionListener(new ActionListener() {@Overridepublic void actionPerformed(ActionEvent e) {jfid.setText("");jfname.setText("");jfage.setText("");jfsex.setText("");jfscore.setText("");jfbirthday.setText("");}});this.setTitle("修改學生信息");this.setLayout(new GridLayout(9,1));this.add(jpid);this.add(jpname);this.add(jpage);this.add(jpsex);this.add(jpscore);this.add(jpbirthday);this.add(jpbutton);this.setLocation(400,300);this.setSize(350,300);this.setVisible(true);}

}

轉載于:https://www.cnblogs.com/Pythons/p/10932308.html

總結

以上是生活随笔為你收集整理的java-Mysql学生管理系统的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。