JAVA学生宿舍管理系统
作者:互联网
转:
JAVA学生宿舍管理系统
需要的工具
1.SQL Server
2.Eclipse
3.JDBC连接数据库驱动
https://download.microsoft.com/download/A/F/B/AFB381FF-7037-46CE-AF9B-6B1875EA81D7/sqljdbc_6.0.8112.200_chs.exe
功能实现
分为三大类
1.land.java (登陆界面)
2.system.java (系统管理界面)
3.sql.java (数据库操作,包括连接、断开、增删改查等操作)
一、登陆界面及代码
部分代码:
登陆按钮事件
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if((JButton)e.getSource()== buttonLand)
{
String name = textName.getText().trim();
String password = String.valueOf(textPassword.getPassword()).trim();
int num = sq.landing(name, password);
if(num==1)
{
JOptionPane.showMessageDialog(frame, "欢迎进入学生宿舍管理系统!","提示:",JOptionPane.PLAIN_MESSAGE);
system system = new system();
frame.dispose();
}
else
{
JOptionPane.showMessageDialog(frame, "账号或者密码错误!","提示:",JOptionPane.ERROR_MESSAGE);
}
}
}
二、系统管理界面及代码**(这里只添加了俩个表,多少表都是一样的道理**)
增加数据:点击增加按钮会出现一空白行,填写完点击保存即可
保存(更新)数据:直接在表中进行相应的操作,再点击保存即可
删除数据:选择某行,点击删除按钮即可
部分代码:
//--------------------------------------按钮事件--------------------------------
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//------------------------------- 删除-----------------------------
String tableName = null;
String key1 = null;
if((JButton)e.getSource()==buttonDelete)
{ if(paneParent.getSelectedIndex()==1)
{
tableName = "学生信息表";
key1 = "sno";
}
if(paneParent.getSelectedIndex()==2)
{
tableName = "宿舍信息表";
key1 = "dno";
}
int row = table.getSelectedRow();
if(row!=-1)
{
String key2 = (String) tableModel.getValueAt(row, 0);
int result = JOptionPane.showConfirmDialog(null, "确定要删除吗?","请确认",JOptionPane.YES_NO_OPTION);
if(result==JOptionPane.OK_OPTION)
{
String sql = "delete from "+tableName+" where "+key1+"="+key2;
int num = sq.delete(sql);
if(num>0)
{
tableModel.removeRow(row);
}
}
}
else
{
JOptionPane.showMessageDialog(null, "请选择要删除的行!","提示:",JOptionPane.ERROR_MESSAGE);
}
}
//------------------------------保存------------------------
if((JButton)e.getSource()==buttonSave)
{
int result = JOptionPane.showConfirmDialog(null, "请确认数值已经更改,否则保存无效","请确认",JOptionPane.YES_NO_OPTION);
if(result==JOptionPane.OK_OPTION)
{
int row = table.getRowCount();
int column = table.getColumnCount();
String[][]valueRow= new String[row][column];
String[] sqlvalue = new String[row];
for(int i = 0; i < row; i++)
{
for(int j = 0; j < column; j++)
{
valueRow[i][j] = table.getValueAt(i, j).toString();
}
}
if(paneParent.getSelectedIndex()==1)
{
for(int i =0;i<row;i++) {="" string="" sql="insert into 学生信息表" +"="" values="" ("+valuerow[i][0].tostring()+","+valuerow[i][1].tostring()+","+valuerow[i][2].tostring()+","+valuerow[i][3].tostring()+","+valuerow[i][4].tostring()+","+valuerow[i][5].tostring()+")";="" sqlvalue[i]="sql.toString();" }="" data="sq.Save(sqlvalue,"学生信息表",row," column);="" tablemodel.setdatavector(data,datatitle);="" if(paneparent.getselectedindex()="=2)" for(int="" i="0;i<row;i++)" ("+valuerow[i][0].tostring()+","+valuerow[i][1].tostring()+")";="" tablemodel.setdatavector(data,titledormitor);="" ------------------------------增加---------------------------="" if((jbutton)e.getsource()="=buttonIncrease)" tablemodel.addrow(new="" vector<="">());
}
}
标签:学生宿舍,JAVA,String,管理系统,int,JOptionPane,num,null,row 来源: https://www.cnblogs.com/wangtcc/p/14448972.html