java宿舍管理系统代码_JAVA学⽣宿舍管理系统需要的⼯具
1.SQL Server
2.Eclipse
3.JDBC连接数据库驱动
功能实现
分为三⼤类
1.land.java (登陆界⾯)
2.system.java (系统管理界⾯)
3.sql.java (数据库操作,包括连接、断开、增删改查等操作)
⼀、登陆界⾯及代码
部分代码:
登陆按钮事件
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if((Source()== buttonLand)
{
generated
String name = Text().trim();
String password = String.Password()).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((Source()==buttonDelete)
{ SelectedIndex()==1)
{
tableName = "学⽣信息表";
key1 = "sno";
}
SelectedIndex()==2)
{
tableName = "宿舍信息表";
key1 = "dno";
}
int row = SelectedRow();
if(row!=-1)
{
String key2 = (String) ValueAt(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)
{
}
}
}
else
{
JOptionPane.showMessageDialog(null, "请选择要删除的⾏!","提⽰:",JOptionPane.ERROR_MESSAGE);
}
}
//------------------------------保存------------------------
if((Source()==buttonSave)
{
int result = JOptionPane.showConfirmDialog(null, "请确认数值已经更改,否则保存⽆效","请确认",JOptionPane.YES_NO_OPTION); if(result==JOptionPane.OK_OPTION)
{
int row = RowCount();
int column = ColumnCount();
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] = ValueAt(i, j).toString();
}
}
SelectedIndex()==1)
{
for(int i =0;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]=String();
}
data = sq.Save(sqlvalue,"学⽣信息表",row, column);
tableModel.setDataVector(data,dataTitle);
}
SelectedIndex()==2)
{
for(int i =0;i
{
String sql = "insert into 宿舍信息表"+" values ("+valueRow[i][0].toString()+","+valueRow[i][1].toString()+")";
sqlvalue[i]=String();
}
data = sq.Save(sqlvalue,"宿舍信息表",row, column);
tableModel.setDataVector(data,TitleDormitor);
}
}
}
//------------------------------增加---------------------------
if((Source()==buttonIncrease)
{
tableModel.addRow(new Vector<>());
}
}
三、sql.java (重要)
public class SQL {
public Connection conn;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。