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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/386738.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/386738.shtml
英文地址,請注明出處:http://en.pswp.cn/news/386738.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Docker版本Jenkins的使用

Docker版本Jenkins的使用 低調的微胖關注贊賞支持 Docker版本Jenkins的使用 12018.05.15 18:21:50字數 1202閱讀 22588 一. 什么是Jenkins Jenkins是當前非常流行的一款持續集成工具,可以幫助大家把更新后的代碼自動部署到服務器上運行。 二. 為什么用docker版…

小程序 setData 中的坑,其實好像...

最近這段時間在寫微信小程序,有一個頁面需要動態修改 data 中的數據,而這里似乎是個坑。 1、正常修改 正常修改很簡單,當觸發 change 事件時,數據和頁面都會同時發生改變。這個也不用多說,很簡單的例子。 2、如何修改對…

CentOS HarBor安裝與配置

HarBor 安裝與配置 Prerequisites for the target host ResourceCapacityDescriptionCPUminimal 2 CPU4 CPU is preferredMemminimal 4GB8GB is preferredDiskminimal 40GB160GB is preferred 環境 centos7harbor v1.6.3python v2.7及以上docker v1.10及以上docker-compose …

冪等

一種方案是創建唯一索引。在數據庫中針對我們需要約束的資源字段創建唯一索引,可以防止插入重復數據。但是,遇到分庫分表的場景,唯一索引也就不那么好使了, 此時,我們可以先查詢數據庫,判斷約束的資源字段是…

ELK 刪除索引只保留10天

delelk.sh: #!/bin/bash #定時清除elk索引,10天 DATEdate -d "10 days ago" %Y.%m.%d curl -XDELETE "http://127.0.0.1:9400/*-${DATE}" 127.0.0.1:9400 ES的地址 定時任務執行此腳本 30 17 * bash /home/scripts/delelk.sh

通過ceph-deploy搭建ceph 13.2.5 mimic

一、ceph介紹 操作系統需要內核版本在kernel 3.10或CentOS7以上版本中部署通過deploy工具安裝簡化部署過程,本文中選用的ceph-deploy版本為1.5.39至少準備6個環境,分別為1個ceph-admin管理節點、3個mon/mgr/mds節點、2個osd節點二、ceph安裝 1. 部署ceph…

openstack服務編排

heat列出所有組件時報錯 ERROR: 503 Service Unavailable The server is currently unavailable. Please try again at a later time. 錯誤:503服務不可用 cu錯 w誤 : 5 0 3 f服 w務 b不 kě可 yng用 The server is currently unavailable. Please tr…

phpstudy如何安裝景安ssl證書 window下apache服務器網站https訪問

1. 下載景安免費證書 https://www.zzidc.com/help/helpDetail?id555 2.文件解壓上傳至服務器,位置自己決定 3. 調整apache配置 景安原文鏈接:https://www.zzidc.com/help/helpDetail?id555 ① 確保你的apache編譯了ssl模塊,這是支持ssl證書…

docker下gitlab安裝配置使用(完整版)

docker下gitlab安裝配置使用(完整版) 22018.12.16 00:07:57字數 737閱讀 17595 docker 安裝gitlab以及使用 一、安裝及配置 1.gitlab鏡像拉取 # gitlab-ce為穩定版本,后面不填寫版本則默認pull最新latest版本 $ docker pull gitlab/gitlab-ce拉取鏡像 2.運行g…

hdfs的特性、命令、安全模式、基準測試

1.第一點:如何理解hdfs分布式文件系統,每臺機器出一塊磁盤,湊成一個大的硬盤,大的硬盤的容量來自各個服務器的硬盤容量之和。 你出5毛,我出5毛,大家湊成1塊。 2. HDFS 是 Hadoop Distribute File System 的…

如何push一個docker鏡像到DockerHub上

如何push一個docker鏡像到DockerHub上 2018.01.03 11:31:39字數 139閱讀 202 有時候想要保存自己的docker鏡像,又不想自己搭建docker registry,那么就可以了借用DockerHub來用,一般不會有多少人在意你的鏡像,不過萬一被人看上了…

測開2 - Python(文件操作)

把第一次寫好漏掉的點寫在最前面:文件讀寫的內容都要求是字符串。 幾種文件操作的模式: 1. r,讀模式(默認模式),只能讀不能寫,文件不存在時報錯 2. w,寫模式,只能寫不能讀…

使用docker在CentOS7上搭建WordPress

前言 本文基于Centos 7 環境的docker搭建操作,centos 7 用 firewalld 替換了iptables作為默認防火墻操作,但以前習慣了iptables 就不與時俱進了。 環境準備 systemctl disable firewalld systemctl stop firewalld setenforce 0 sed -i "s/SELIN…

企業級應用,如何實現服務化一(項目架構演化)

1.企業級應用架構演化 1.1.架構演化圖 1.2.文字描述 #單一應用架構當網站流量很小時,只需一個應用,將所有功能都部署在一起,以減少部署節點和成本#垂直應用架構當訪問量逐漸增大,單一應用增加機器帶來的加速度越來越小&#xff0c…

Alpine 操作系統是一個面向安全的輕型 Linux 發行版

Alpine 操作系統是一個面向安全的輕型 Linux 發行版。它不同于通常 Linux 發行版,Alpine 采用了 musl libc 和 busybox 以減小系統的體積和運行時資源消耗,但功能上比 busybox 又完善的多,因此得到開源社區越來越多的青睞。在保持瘦身的同時&…

ASP.NET MVC Filter過濾機制(過濾器、攔截器)

https://blog.csdn.net/knqiufan/article/details/82413885 本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/knqiufan/article/details/82413885參考文章:1、https://www.cnblogs.com/webapi/p/5669057.html 2、htt…

elk docker

換了個運行環境,重新搭建一套公司本地內部的ELK,之前也搭過(可訪問:https://yanganlin.com/31.html),最近做什么事情都想用Docker,這次也用Docker,還算順利,沒掉什么坑里,上次搭建,也用用的6.2的版本,這都過了一年,Elk這三個產品,都已經上7了,用docker搭建的還是用6.2.4,穩定不…

LeetCode Largest Number

1231231轉載于:https://www.cnblogs.com/ZHONGZHENHUA/p/10954249.html

有個需求mybatis?插入的時候不知道有哪些字段,需要動態的傳入值和字段

有個需求mybatis 插入的時候不知道有哪些字段,需要動態的傳入值和字段, Java code? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Test public void testAddProductGuaranty() { //1 560 50000 2014/10/2 0:00:00 2014/11/1 0…

readonly的用法

轉載于:https://www.cnblogs.com/w123w/p/10958567.html