数据库在regediter中userinfo_Data
谢谢了!
[此贴子已经被作者于2006-12-23 17:42:00编辑过]
[此贴子已经被作者于2006-12-23 17:42:00编辑过]
//添加数据
public boolean add(){
boolean flag=false;
try{
this.getConnection();
ps=con.prepareStatement("insert into userinfo values(?,?,?)");
ps.setString(1,getName());
ps.setString(2,getPassword());
ps.setString(3,getAddress());
rs=ps.executeQuery();
flag=true;
}catch(Exception ex){
ex.printStackTrace();
}
finally{
this.closeData();
}
return flag;
//调用代码
public void btadd_actionPerformed(ActionEvent e) {
database db = new database();
db.setName(this.txtyhm.getText().trim());
db.setPassword(this.txtmm.getText().trim());
db.setAddress(this.txtaddress.getText().trim());
if (db.getName().equals("")) {
JOptionPane.showMessageDialog(this, "用户名为空", "错误信息",
JOptionPane.ERROR_MESSAGE);
}
else {
if (db.getPassword().equals("")) {
JOptionPane.showMessageDialog(this, "密码为空", "错误信息",
JOptionPane.ERROR_MESSAGE);
}
else {
if (db.getAddress().equals("")) {
JOptionPane.showMessageDialog(this, "地址为空", "错误信息",
JOptionPane.ERROR_MESSAGE);
}
else {
if (db.search()) {
JOptionPane.showMessageDialog(this, "数据库中已经存在该用户名", "错误信息",
JOptionPane.ERROR_MESSAGE);
}
else {
db.add();
JOptionPane.showMessageDialog(this, "恭喜,添加成功", "弹出信息",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
}
//查找信息
public boolean search(){
boolean flag=false;
try{
this.getConnection();
ps=con.prepareStatement("select * from userinfo where name=?");
ps.setString(1,getName());
rs=ps.executeQuery();
if(rs.next()){
flag = true;
}
}catch(Exception ex){
ex.printStackTrace();
}
finally{
this.closeData();
}
return flag;
}