tString("name"));
}
conn.dbClose(rs);
conn=null;
}
catch(Exception e){}
}
public void actionPerformed(ActionEvent ee){
if(ee.getActionCommand().equals("退出"))
dispose();
if(ee.getActionCommand().equals("增加")){
sql="select * from users where name='"+nameTxt.getText()+"'";
conn=new sqlconn();
try{
rs=conn.getRs(sql);
if(rs.next()){
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"该用户已经存在!","警告",1);
conn.dbClose(rs);
conn=null;
rs=null;
}
else{
try{
sql="insert into users values('"+nameTxt.getText()+"','"+pwdTxt.getText()+"')";
conn=new
sqlconn();
conn.dbMod(sql);
conn.dbClose(rs);
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"添加成功!","提示信息",1);
}
catch(Exception se){}
userChoice.addItem(nameTxt.getText());
nameTxt.setText("");
pwdTxt.setText("");
conn=null;
}
}catch(Exception a){}
}
if(ee.getActionCommand().equals("修改")){
sql="select * from users where name='"+nameTxt.getText()+"'";
conn=new sqlconn();
try{
rs=conn.getRs(sql);
if(!(rs.next())){
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"用户不存在,修改失败!","警告",1);
conn.dbClose(rs);
sql="";
conn=null;
rs=null;
return ;
}
}
catch(Exception exc){}
try{
sql="update users set password='"+pwdTxt.getText()+"'where name='"+nameTxt.getText()+"'";
conn=new sqlconn();
conn.dbMod(sql);
conn.dbClose(rs);
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"修改成功!","提示信息",1);
}
catch(Exception se){}
nameTxt.setText("");
pwdTxt.setText("");
conn=null;
}
if(ee.getActionCommand().equals("删除")){
JOptionPane jopask=new JOptionPane();
if(jopask.showConfirmDialog(null,"你确定要删除此记录吗?","请确认",1)==0){
sql="select * from users where name='"+nameTxt.getText()+"'";
conn=new sqlconn();
try{
rs=conn.getRs(sql);
if(!(rs.next())){
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"用户不存在,删除失败!","警告",1);
conn.dbClose(rs);
sql="";
conn=null;
rs=null;
return ;
}
}
catch(Exception exc){}
try{
conn=new sqlconn();
sql="delete from users where name='"+nameTxt.getText()+"'";
conn.dbMod(sql);
conn.dbClose(rs);
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(null,"删除成功!","提示信息",1);
}
catch(Exception se){}
conn=null;
userChoice.remove(userChoice.getSelectedIndex());
nameTxt.setText("");
pwdTxt.setText("");
}
}
//把用户
列表的第一用户名赋值给nameTxt文本框
public void itemStateChanged(ItemEvent ie){
nameTxt.setText(userChoice.getSelectedItem());
try{
conn=new sqlconn();//连接数据库
sql="select password from users";/