当前位置:网站首页>Database dormitory management system
Database dormitory management system
2022-07-21 23:56:00 【A couch potato who doesn't like lying in bed】
C/S Structural design database dormitory management system
Mainly used Java.swing And sql server Designed dormitory management system , There are some problems, welcome to correct .
Database settings
Connect to database (JDBC)
See how to connect to the database :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(" Failed to connect to database !");
}
}
}
Interface settings
mainDisp class :
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(" Sushi ");
jb2=new JButton(" Student ");
jp1=new JPanel();
jp2=new JPanel();
jp3=new JPanel();
jl1=new JLabel(" Dormitory management system ");
jl2=new JLabel(" Please select login identity ");
jl1.setFont(new Font(" Chinese Songti ",Font.BOLD|Font.PLAIN,40));
jl1.setForeground(Color.black);
jl2.setFont(new Font(" Chinese Songti ",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(" The user login ");
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 :
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={
"--- Please select the query method ---"," Query by dormitory "," By student number "};
public dormSearch(){
super();
setLayout(new BorderLayout());
setTitle(" Check in information ");
setSize(500,300);
setLocationRelativeTo(null);
jt=new JTextField(10);
jb = new JButton(" Inquire about ");
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);
// Get the number and name of columns in the table , As the title of the table component
ResultSetMetaData rsmd=res.getMetaData();
// Get the number of columns
int count=rsmd.getColumnCount();
Add column names to the table model as headings
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);
// Add a row
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);
// Get the number and name of columns in the table , As the title of the table component
ResultSetMetaData rsmd=res.getMetaData();
// Get the number of columns
int count=rsmd.getColumnCount();
Add column names to the table model as headings
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);
// Add a row
model.addRow(row);
}
res.close();
}catch(Exception ei) {
ei.printStackTrace();
}
}
}
}
effect :
Program download :https://download.csdn.net/download/weixin_45330449/12589569
GitHub download :https://github.com/As-Zach/Demo/blob/master/GUIdemo.zip
边栏推荐
- English abbreviation of team members
- 【Jmeter配置元件之csv数据文件配置】
- LR load balancer management, distributed load generator
- SQL SELECT statement
- Special test of APP compatibility
- [common interview questions of network protocol]
- LoadRunner clears browser cache
- Common methods and applications of request
- Navicat 16.1 provides a new choice of management development tools for oceanbase Community Edition
- Dry goods | overview of RDBMS index types
猜你喜欢
【软件测试模型进化】
Lamp Architecture - MySQL router (read / write separator)
Day03 test case knowledge points summary (Part 2)
JMeter之聚合报告
About the solution of "indentation error: unindent does not match any outside indentation level"
The shortcomings of LVS and the fourth forwarding type fullnat
Common functions of Charles
Architecture lamp - routeur MySQL (séparateur lecture - écriture)
根据进程名一键批量结束进程(chromedriver.exe)
Dry goods | overview of RDBMS index types
随机推荐
Lamp架构——mysql集群及组复制(3)
实现页面与页面之间的信息交换
LVS的不足之处及第四种转发类型FULLNAT
Lamp架构——mysql高可用切换(MHA高可用)
Set up form
[software test model evolution]
What to do if the research and development quality is poor
知秋
Peoplecode assigns values based on context references
Test point exercise
Practical exercise | export MySQL tables to CSV
LR load balancer management, distributed load generator
Centos7 configuring MySQL multiple instances
Install cross compiler: eabi-4.3.3_ EmbedSky_ 20100610.tar. bz2
软件测试面试题与答案【一】
JMeter read response header information / get request header
Analysis of cross apply and outer apply query of SQL Server - Part I
Name reference defined by peoplecode
Pycharm 2019使用设置,让你用起来更便捷!
English abbreviation of team members