Java+mysql實(shí)現(xiàn)學(xué)籍管理系統(tǒng)
本文實(shí)例為大家分享了Java+mysql實(shí)現(xiàn)學(xué)籍管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、myswql數(shù)據(jù)庫(kù)表格
項(xiàng)目使用mysql數(shù)據(jù)庫(kù),有2張表格。一張用戶表用于登錄驗(yàn)證,一張學(xué)生表,用于增刪改查。
creat table t_user( id int primary key auto_increment, login_name varchar(255), login_pwd ?varchar(255), real_name varchar(255), ); insert into t_user(id,login_name,login_pwd,real_name) values('akm',"123",'蘿卜蹲'); CREATE TABLE t_user( ?id char(12) PRIMARY KEY, ?name char(6), ?pwd varchar(255), );
二、功能實(shí)現(xiàn)
1.實(shí)際演示
1.1登錄界面
在用戶爛輸入:akm
密碼欄輸入:123
點(diǎn)擊登錄按鈕,就可以直接進(jìn)入系統(tǒng)。
如果輸入錯(cuò)誤,狀態(tài)欄會(huì)顯示登錄失敗,并清空登錄賬戶和密碼。
1.2系統(tǒng)主界面
系統(tǒng)主界面由5個(gè)按鈕組成
添加學(xué)生信息,在主界面中選擇添加按鈕并點(diǎn)擊進(jìn)入添加界面,如上圖所示。在界面中添加相應(yīng)的學(xué)生信息,id,姓名,年齡 學(xué)籍等。
1.3查詢信息
通過(guò)id查詢學(xué)生信息。
1.4遍歷信息
1.5 刪除信息
輸入id直接刪除。
1.6 更新信息
2.test.java文件源碼
項(xiàng)目只有一個(gè)test文件,沒(méi)有封裝,有需要的小伙伴可以自己進(jìn)行封裝。
代碼如下:
package com.company; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.sql.Statement; import java.util.Scanner; public class Test { ? ? static ?Connection conn ; ? ? static Statement statement; ? ? public static void main(String[] args) { ? ? ? ? Scanner in = new Scanner(System.in); ? ? ? ? login(); ? ? ? ? } ? ? public static void control() { ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 300, 200); ? ? ? ? JButton button = new JButton("更新"); ? ? ? ? JButton button1=new JButton("遍歷"); ? ? ? ? JButton button2=new JButton("刪除"); ? ? ? ? JButton button3=new JButton("添加"); ? ? ? ? JButton button4=new JButton("查詢"); ? ? ? ? jf.add(button); ? ? ? ? jf.add(button1); ? ? ? ? jf.add(button2); ? ? ? ? jf.add(button3); ? ? ? ? jf.add(button4); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? update(); ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? button1.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? query(); ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? button2.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? delete(); ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? button3.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? insert(); ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? button4.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) {onequery();} ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static void update() { ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 300, 200); ? ? ? ? JLabel label1 = new JLabel("年齡"); ? ? ? ? JTextField agetext = new JTextField("", 10); ? ? ? ? JLabel label2 = new JLabel("id"); ? ? ? ? JTextField idtext = new JTextField("", 10); ? ? ? ? JLabel label3 = new JLabel("學(xué)籍"); ? ? ? ? JTextField addresstext = new JTextField("", 10); ? ? ? ? JLabel label4 = new JLabel("姓名"); ? ? ? ? JTextField nametext = new JTextField("", 5); ? ? ? ? JTextField out = new JTextField("更新狀態(tài)", 20); ? ? ? ? JButton button = new JButton("更新"); ? ? ? ? jf.add(label1); ? ? ? ? jf.add(agetext); ? ? ? ? jf.add(label2); ? ? ? ? jf.add(idtext); ? ? ? ? jf.add(label3); ? ? ? ? jf.add(addresstext); ? ? ? ? jf.add(label4); ? ? ? ? jf.add(nametext); ? ? ? ? jf.add(out); ? ? ? ? jf.add(button); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? String age = agetext.getText(); ? ? ? ? ? ? ? ? String id = idtext.getText(); ? ? ? ? ? ? ? ? String address= addresstext.getText(); ? ? ? ? ? ? ? ? String name=nametext.getText(); ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? // 更新數(shù)據(jù)的sql語(yǔ)句 ? ? ? ? ? ? ? ? ? ? String sql = "update student set age =? , address =?, name=? where ?id = ?"; ? ? ? ? ? ? ? ? ? ? ps=conn.prepareStatement(sql); ? ? ? ? ? ? ? ? ? ? ps.setString(1,agetext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(2,addresstext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(3,nametext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(4,idtext.getText()); ? ? ? ? ? ? ? ? ? ? int count = ps.executeUpdate();//記錄操作次數(shù) ? ? ? ? ? ? ? ? ? ? // 輸出插入操作的處理結(jié)果 ? ? ? ? ? ? ? ? ? ? System.out.println("user表中更新 " + count + " 條數(shù)據(jù)"); ? ? ? ? ? ? ? ? ? ? ps.close(); ? ? ? ? ? ? ? ? ? ? //關(guān)閉數(shù)據(jù)庫(kù)連接 ? ? ? ? ? ? ? ? ? ? conn.close(); ? ? ? ? ? ? ? ? ? ? out.setText("更新成功!?。。。。。?!"); ? ? ? ? ? ? ? ? ? ? // 創(chuàng)建用于執(zhí)行靜態(tài)sql語(yǔ)句的Statement對(duì)象,st屬局部變量 ? ? ? ? ? ? ? ? } catch (SQLException a) { ? ? ? ? ? ? ? ? ? ? System.out.println("更新數(shù)據(jù)失敗"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static void query() { ? ? ? ? PreparedStatement ps=null; ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(null); ? ? ? ? jf.setBounds(400, 300, 350, 200); ? ? ? ? JButton button = new JButton("查詢"); ? ? ? ? JTextArea jm=new JTextArea("ID\t姓名\t年齡\t學(xué)籍");//顯示界面 ? ? ? ? jm.setBounds(10,50,350,100);//定義顯示界面位置 ? ? ? ? jf.add(button); ? ? ? ? jf.add(jm); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? String sql = "select * from Student"; ? ? ? ? ? ? ? ? ? ? //創(chuàng)建用于執(zhí)行靜態(tài)sql語(yǔ)句的Statement對(duì)象,statement屬局部變量 ? ? ? ? ? ? ? ? ? ? statement = conn.createStatement();//獲取操作對(duì)象 ? ? ? ? ? ? ? ? ? ? ResultSet resultSet = statement.executeQuery(sql);// executeQuery執(zhí)行單個(gè)SQL語(yǔ)句,返回單個(gè)ResultSet對(duì)象是 ? ? ? ? ? ? ? ? ? ? while (resultSet.next())//循環(huán)沒(méi)有數(shù)據(jù)的時(shí)候返回flase退出循環(huán) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? Integer Id = resultSet.getInt("id");//resultSet.next()是一個(gè)光標(biāo) ? ? ? ? ? ? ? ? ? ? ? ? String name = resultSet.getString("name");//getString返回的值一定是string ? ? ? ? ? ? ? ? ? ? ? ? Integer age = resultSet.getInt("age"); ? ? ? ? ? ? ? ? ? ? ? ? String address=resultSet.getString("address"); ? ? ? ? ? ? ? ? ? ? ? ? //String adress = resultSet.getString("adress"); ? ? ? ? ? ? ? ? ? ? ? ? //輸出查到的記錄的各個(gè)字段的值 ? ? ? ? ? ? ? ? ? ? ? ? jm.append("\n"+Id + "\t" + name + "\t" + age+ "\t" + address ); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? statement.close(); ? ? ? ? ? ? ? ? ? ? conn.close(); ? ? ? ? ? ? ? ? }catch (SQLException b){ ? ? ? ? ? ? ? ? ? ? System.out.println("查詢失?。。。。。。。?!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static void delete() { ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 300, 200); ? ? ? ? JLabel label2 = new JLabel("id"); ? ? ? ? JTextField idtext = new JTextField("", 10); ? ? ? ? JTextField out = new JTextField("刪除狀態(tài)", 20); ? ? ? ? JButton button = new JButton("刪除"); ? ? ? ? jf.add(label2); ? ? ? ? jf.add(idtext); ? ? ? ? jf.add(out); ? ? ? ? jf.add(button); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? String id = idtext.getText(); ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? // 刪除數(shù)據(jù)的sql語(yǔ)句 ? ? ? ? ? ? ? ? ? ? String sql = "delete from Student ?where id = ?"; ? ? ? ? ? ? ? ? ? ? ps=conn.prepareStatement(sql); ? ? ? ? ? ? ? ? ? ? ps.setString(1,idtext.getText()); ? ? ? ? ? ? ? ? ? ? int count = ps.executeUpdate();//記錄操作次數(shù) ? ? ? ? ? ? ? ? ? ? // 輸出插入操作的處理結(jié)果 ? ? ? ? ? ? ? ? ? ? System.out.println("student表中刪除 " + count + " 條數(shù)據(jù)"); ? ? ? ? ? ? ? ? ? ? ps.close(); ? ? ? ? ? ? ? ? ? ? out.setText("刪除成功!?。。。。。?!"); ? ? ? ? ? ? ? ? ? ? // 關(guān)閉數(shù)據(jù)庫(kù)連接 ? ? ? ? ? ? ? ? ? ? conn.close(); ? ? ? ? ? ? ? ? } catch (SQLException c) { ? ? ? ? ? ? ? ? ? ? System.out.println("刪除數(shù)據(jù)失敗"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static void insert() { ? ? ? ? // 首先要獲取連接,即連接到數(shù)據(jù)庫(kù) ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 300, 200); ? ? ? ? JLabel label3 = new JLabel("id"); ? ? ? ? JTextField idtext = new JTextField("", 10); ? ? ? ? JLabel label1 = new JLabel("年齡"); ? ? ? ? JTextField agetext = new JTextField("", 10); ? ? ? ? JLabel label2 = new JLabel("姓名"); ? ? ? ? JTextField nametext = new JTextField("", 10); ? ? ? ? JLabel label4 = new JLabel("學(xué)籍"); ? ? ? ? JTextField addresstext = new JTextField("", 5); ? ? ? ? JTextField out = new JTextField("添加狀態(tài)", 20); ? ? ? ? JButton button = new JButton("添加"); ? ? ? ? jf.add(label3); ? ? ? ? jf.add(idtext); ? ? ? ? jf.add(label1); ? ? ? ? jf.add(agetext); ? ? ? ? jf.add(label2); ? ? ? ? jf.add(nametext); ? ? ? ? jf.add(label4); ? ? ? ? jf.add(addresstext); ? ? ? ? jf.add(out); ? ? ? ? jf.add(button); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? String age = agetext.getText(); ? ? ? ? ? ? ? ? String name = nametext.getText(); ? ? ? ? ? ? ? ? String ?id=idtext.getText(); ? ? ? ? ? ? ? ? String address=addresstext.getText(); ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? ? ? // 插入數(shù)據(jù)的sql語(yǔ)句 ? ? ? ? ? ? ? ? ? ? String sql = "INSERT INTO Student( id,age,name,address) VALUES ( ?,?,?,?)"; ? ? ? ? ? ? ? ? ? ? ps=conn.prepareStatement(sql); ? ? ? ? ? ? ? ? ? ? ps.setString(1,idtext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(2,agetext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(3,nametext.getText()); ? ? ? ? ? ? ? ? ? ? ps.setString(4,addresstext.getText()); ? ? ? ? ? ? ? ? ? ? int count = ps.executeUpdate();//記錄操作次數(shù) ? ? ? ? ? ? ? ? ? ? // 輸出插入操作的處理結(jié)果 ? ? ? ? ? ? ? ? ? ? System.out.println("向user表中插入 " + count + " 條數(shù)據(jù)"); ? ? ? ? ? ? ? ? ? ? ps.close(); ? ? ? ? ? ? ? ? ? ? out.setText("添加成功?。。。。。。。?); ? ? ? ? ? ? ? ? ? ? // 關(guān)閉數(shù)據(jù)庫(kù)連接 ? ? ? ? ? ? ? ? ? ? conn.close(); ? ? ? ? ? ? ? ? } catch (SQLException d) { ? ? ? ? ? ? ? ? ? ? System.out.println("插入數(shù)據(jù)失敗" + d.getMessage()); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static boolean login(){ ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 300, 200); ? ? ? ? JLabel label1 = new JLabel("用戶名"); ? ? ? ? JTextField usernametext = new JTextField("", 20); ? ? ? ? JLabel label2 = new JLabel("密碼"); ? ? ? ? JPasswordField pwdtext = new JPasswordField("", 20); ? ? ? ? JTextField out = new JTextField("登錄狀態(tài)", 20); ? ? ? ? JButton button = new JButton("登錄"); ? ? ? ? jf.add(label1); ? ? ? ? jf.add(usernametext); ? ? ? ? jf.add(label2); ? ? ? ? jf.add(pwdtext); ? ? ? ? jf.add(out); ? ? ? ? jf.add(button); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? // 插入數(shù)據(jù)的sql語(yǔ)句 ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? statement = conn.createStatement();//獲取操作對(duì)象 ? ? ? ? ? ? ? ? ? ? String x = usernametext.getText(); ? ? ? ? ? ? ? ? ? ? String y = pwdtext.getText(); ? ? ? ? ? ? ? ? ? ? String sql ="select * from user"; ? ? ? ? ? ? ? ? ? ? ResultSet resultSet = statement.executeQuery(sql); ? ? ? ? ? ? ? ? ? ? while(resultSet.next()){ ? ? ? ? ? ? ? ? ? ? ? ? String a=resultSet.getString("login_name"); ? ? ? ? ? ? ? ? ? ? ? ? String b=resultSet.getString("login_pwd"); ? ? ? ? ? ? ? ? ? ? ? ? if(a.equals(x)&&b.equals(y)) ? ? ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? ? ? control(); ? ? ? ? ? ? ? ? ? ? ? ? ? ? out.setText("!!!!!登錄成功!!!!!"); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? ? ? else if(x!=a&&y!=b){ ? ? ? ? ? ? ? ? ? ? ? ? ? ? out.setText("登錄失敗,請(qǐng)重新輸入"); ? ? ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? usernametext.setText(""); ? ? ? ? ? ? ? ? ? ? pwdtext.setText(""); ? ? ? ? ? ? ? ? } catch (SQLException throwables) { ? ? ? ? ? ? ? ? ? ? throwables.printStackTrace(); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? ? ? boolean ok = true; ? ? ? ? return ok; ? ? } ? ? public static void onequery() { ? ? ? ? PreparedStatement ps=null; ? ? ? ? conn = getConnection(); ? ? ? ? JFrame jf = new JFrame("學(xué)生學(xué)籍管理系統(tǒng)"); ? ? ? ? jf.setLayout(new FlowLayout(FlowLayout.LEFT)); ? ? ? ? jf.setBounds(400, 300, 350, 200); ? ? ? ? JLabel label3 = new JLabel("id"); ? ? ? ? JTextField idtext = new JTextField("", 10); ? ? ? ? JLabel label1 = new JLabel("條件"); ? ? ? ? JTextField atext = new JTextField("", 10); ? ? ? ? JButton button = new JButton("查詢"); ? ? ? ? //JTextArea jm=new JTextArea("ID\t姓名\t年齡\t學(xué)籍");//顯示界面 ? ? ? ? //jm.setBounds(10,50,350,100);//定義顯示界面位置 ? ? ? ? jf.add(label3); ? ? ? ? jf.add(idtext); ? ? ? ? jf.add(button); ? ? ? ? //jf.add(jm); ? ? ? ? button.addActionListener(new ActionListener() { ? ? ? ? ? ? @Override ? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ? ? ? ? ? ? ? ? PreparedStatement ps=null; ? ? ? ? ? ? ? ? String id=idtext.getText(); ? ? ? ? ? ? ? ? conn = getConnection(); ? ? ? ? ? ? ? ? try { ? ? ? ? ? ? ? ? ? ? String sql = "select * from student where id = ?"; ? ? ? ? ? ? ? ? ? ? //創(chuàng)建用于執(zhí)行靜態(tài)sql語(yǔ)句的Statement對(duì)象,statement屬局部變量 ? ? ? ? ? ? ? ? ? ? ps=conn.prepareStatement(sql);//獲取操作對(duì)象 ? ? ? ? ? ? ? ? ? ? ps.setString(1,idtext.getText().toString()); ? ? ? ? ? ? ? ? ? ? ResultSet resultSet = ?ps.executeQuery();// executeQuery執(zhí)行單個(gè)SQL語(yǔ)句,返回單個(gè)ResultSet對(duì)象是 ? ? ? ? ? ? ? ? ? ? while (resultSet.next())//循環(huán)沒(méi)有數(shù)據(jù)的時(shí)候返回flase退出循環(huán) ? ? ? ? ? ? ? ? ? ? { ? ? ? ? ? ? ? ? ? ? ? ? Integer Id = resultSet.getInt("id");//resultSet.next()是一個(gè)光標(biāo) ? ? ? ? ? ? ? ? ? ? ? ? String name = resultSet.getString("name");//getString返回的值一定是string ? ? ? ? ? ? ? ? ? ? ? ? Integer age = resultSet.getInt("age"); ? ? ? ? ? ? ? ? ? ? ? ? String address=resultSet.getString("address"); ? ? ? ? ? ? ? ? ? ? ? ? System.out.println(Id + " " + name + " " + age + " "+ address + " " ); ? ? ? ? ? ? ? ? ? ? ? ? //輸出查到的記錄的各個(gè)字段的值 ? ? ? ? ? ? ? ? ? ? ? ? //jm.append("\n"+Id + "\t" + name + "\t" + age+ "\t" + address ); ? ? ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? ? ? ? statement.close(); ? ? ? ? ? ? ? ? ? ? conn.close(); ? ? ? ? ? ? ? ? }catch (SQLException m){ ? ? ? ? ? ? ? ? ? ? System.out.println(m.getMessage()); ? ? ? ? ? ? ? ? ? ? System.out.println("查詢失?。。。。。。。?!"); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? } ? ? ? ? }); ? ? ? ? jf.setVisible(true); ? ? ? ? jf.setResizable(false); ? ? ? ? button.setSize(40, 20); ? ? ? ? jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ? ? } ? ? public static Connection getConnection(){ ? ? ? ? //創(chuàng)建用于連接數(shù)據(jù)庫(kù)的Connection對(duì)象 ? ? ? ? Connection connection = null; ? ? ? ? try { ? ? ? ? ? ? // 加載Mysql數(shù)據(jù)驅(qū)動(dòng) ? ? ? ? ? ? Class.forName("com.mysql.cj.jdbc.Driver"); ? ? ? ? ? ? System.out.println("數(shù)據(jù)庫(kù)驅(qū)動(dòng)加載成功"); ? ? ? ? ? ? String url = "jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"; ? ? ? ? ? ? // 創(chuàng)建數(shù)據(jù)連接 ? ? ? ? ? ? connection = DriverManager.getConnection(url, "root", "root"); ? ? ? ? ? ? System.out.println("數(shù)據(jù)庫(kù)連接成功"); ? ? ? ? }catch (ClassNotFoundException | SQLException e){ ? ? ? ? ? ? System.out.println("數(shù)據(jù)庫(kù)連接失敗" + e.getMessage());//處理查詢結(jié)果 ? ? ? ? } ? ? ? ? return connection; ? ? } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Java超詳細(xì)教你寫一個(gè)學(xué)籍管理系統(tǒng)案例
- Java實(shí)現(xiàn)簡(jiǎn)易學(xué)籍管理系統(tǒng)
- java實(shí)現(xiàn)簡(jiǎn)易的學(xué)籍管理系統(tǒng)
- java實(shí)現(xiàn)學(xué)籍管理系統(tǒng)
- Java+Mysql學(xué)生管理系統(tǒng)源碼
- javaWeb實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)
- Java+MySQL實(shí)現(xiàn)學(xué)生信息管理系統(tǒng)源碼
- java學(xué)生管理系統(tǒng)界面簡(jiǎn)單實(shí)現(xiàn)(全)
- java學(xué)生信息管理系統(tǒng)源代碼
- java基于控制臺(tái)的學(xué)生學(xué)籍管理系統(tǒng)
相關(guān)文章
解決微服務(wù)feign調(diào)用添加token的問(wèn)題
這篇文章主要介紹了解決微服務(wù)feign調(diào)用添加token的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-06-06SpringMVC中的DispatcherServlet結(jié)構(gòu)和初始化詳解
這篇文章主要介紹了SpringMVC中的DispatcherServlet結(jié)構(gòu)和初始化詳解,SpringMVC中Spring容器的關(guān)系是通過(guò)監(jiān)聽方式啟動(dòng)的,那么Spring與Servlet的Web容器(如:Tomcat、jetty)的關(guān)系則是通過(guò)DispatcherServlet進(jìn)行關(guān)聯(lián),需要的朋友可以參考下2024-01-01一文搞懂Spring中@Autowired和@Resource的區(qū)別
@Autowired?和?@Resource?都是?Spring/Spring?Boot?項(xiàng)目中,用來(lái)進(jìn)行依賴注入的注解。它們都提供了將依賴對(duì)象注入到當(dāng)前對(duì)象的功能,但二者卻有眾多不同,并且這也是常見的面試題之一,所以我們今天就來(lái)盤它2022-08-08SpringSceurity實(shí)現(xiàn)短信驗(yàn)證碼功能的示例代碼
這篇文章主要介紹了SpringSceurity實(shí)現(xiàn)短信驗(yàn)證碼功能的示例代碼,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06