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

歡迎訪問 生活随笔!

生活随笔

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

windows

数据库宿舍管理系统

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

C/S結構設計數據庫宿舍管理系統

主要利用Java.swing與sql server設計的宿舍管理系統,存在一些問題歡迎指正。

數據庫設置

連接數據庫(JDBC)

如何連接數據庫請看:https://blog.csdn.net/weixin_45330449/article/details/107207913

package GUIdemo1;import java.sql.Connection; import java.sql.DriverManager;public class DBconnect {Connection dbConn;public DBconnect(){try {Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");String dbURL = "jdbc:sqlserver://127.0.0.1:1433;DatabaseName=SSGL";dbConn = DriverManager.getConnection(dbURL, "sa", "sa");}catch(Exception ei) {ei.printStackTrace();System.out.println("連接數據庫失敗!");}} }

界面設置


mainDisp類:

public class mainDisp extends JFrame{JButton jb1,jb2;JPanel jp1,jp2,jp3;JLabel jl1,jl2;DBconnect DB = new DBconnect();public mainDisp() {super();jb1=new JButton("宿管");jb2=new JButton("學生");jp1=new JPanel();jp2=new JPanel();jp3=new JPanel();jl1=new JLabel("宿舍管理系統");jl2=new JLabel("請選擇登錄身份");jl1.setFont(new Font("華文宋體",Font.BOLD|Font.PLAIN,40));jl1.setForeground(Color.black);jl2.setFont(new Font("華文宋體",Font.BOLD|Font.PLAIN,20));jl2.setForeground(Color.blue);jp1.add(jl1);jp2.add(jl2);jp3.add(jb1);jp3.add(jb2);setLayout(new GridLayout(3,1));add(jp1);add(jp2);add(jp3);setTitle("用戶登錄");setSize(400,300);setLocationRelativeTo(null);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);jb1.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {setVisible(false);new dormitoryLogin();}});jb2.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {setVisible(false);new studentLogin();}});}public static void main(String[] args) {new mainDisp();} }

dormSearch類:

class dormSearch extends JDialog implements ActionListener {private JTextField jt;private JButton jb;private JComboBox cmb;private JPanel jp;private JTable table;private DefaultTableModel model;private DBconnect DB = new DBconnect();private String[] srr={"---請選擇查詢方式---","按宿舍查詢","按學號查詢"};public dormSearch(){super();setLayout(new BorderLayout());setTitle("入住信息查詢");setSize(500,300);setLocationRelativeTo(null);jt=new JTextField(10);jb = new JButton("查詢");jp = new JPanel();model=new DefaultTableModel();table=new JTable();table.setModel(model);JScrollPane jsp=new JScrollPane(table);cmb = new JComboBox(srr);add(jp,BorderLayout.NORTH);add(jsp,BorderLayout.CENTER);jp.add(cmb);jp.add(jt);jp.add(jb);jb.addActionListener(this);setVisible(true);}public void actionPerformed(ActionEvent e) {if (cmb.getSelectedIndex()==2) {model.setRowCount(0);model.setColumnCount(0);try {String str1=jt.getText();String sql = "select * from stay_info where Stu_num="+str1;Statement statement = DB.dbConn.createStatement();ResultSet res=statement.executeQuery(sql);//獲取表中列數及列名,作為表格組件的標題ResultSetMetaData rsmd=res.getMetaData();//獲得列數int count=rsmd.getColumnCount();將列名添加到表格模型作為標題for(int i=1;i<=count;i++){model.addColumn(rsmd.getColumnName(i));}String[] row=new String[count];while(res.next()){for(int i=0;i<count;i++)row[i]=res.getString(i+1);//增加一行model.addRow(row);}res.close();} catch (Exception ei) {ei.printStackTrace();}}else if (cmb.getSelectedIndex()==1){model.setRowCount(0);model.setColumnCount(0);try {String str1=jt.getText();String sql="select * from stay_info where Dorm_num="+str1;Statement statement=DB.dbConn.createStatement();ResultSet res=statement.executeQuery(sql);//獲取表中列數及列名,作為表格組件的標題ResultSetMetaData rsmd=res.getMetaData();//獲得列數int count=rsmd.getColumnCount();將列名添加到表格模型作為標題for(int i=1;i<=count;i++){model.addColumn(rsmd.getColumnName(i));}String[] row=new String[count];while(res.next()){for(int i=0;i<count;i++)row[i]=res.getString(i+1);//增加一行model.addRow(row);}res.close();}catch(Exception ei) {ei.printStackTrace();}}} }

效果:



程序下載:https://download.csdn.net/download/weixin_45330449/12589569
GitHub下載:https://github.com/As-Zach/Demo/blob/master/GUIdemo.zip

總結

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

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