📄 douser.java
字号:
package cn.aiqinzhe;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DoUser extends ExeDB{
private ResultSet rs ;
private String strSql;
private String id;
public DoUser()
{
this.strSql="";
this.id="";
this.rs=null;
}
//取得所有用户
public ResultSet getUsers()
{
this.strSql="select * from users order by id asc";
rs= super.exeSqlQuery(this.strSql);
return rs;
}
//取得单个用户
public UserDX getUser(int id)throws SQLException
{
try
{
this.strSql="select * from users";
this.strSql=this.strSql + " where id='" + id + "'";
rs= super.exeSqlQuery(this.strSql);
if(rs.next())
{
UserDX udx= new UserDX(rs.getInt(1),
rs.getString(2),
rs.getString(3),
rs.getString(4),
rs.getString(5),
rs.getString(6),
rs.getString(7),
rs.getString(8),
rs.getFloat(9),
rs.getDate(10));
return udx;
}
else return new UserDX();
}catch(Exception ex)
{
System.out.println(ex.toString());
return new UserDX();
}
}
// 添加新用户
public boolean addUser(String name,String pass,String sex,String dianhua,String dizhi,String email,String beizhu)
{
this.strSql="insert into users ";
this.strSql=this.strSql + "(name,pass,sex,dianhua,dizhi,email,beizhu) ";
this.strSql=this.strSql + "values('" + name + "','" + pass + "','" + sex + "','" + dianhua + "','" + dizhi + "','" + email + "','" + beizhu +"')";
boolean aa = super.exeSql(this.strSql);
return aa;
}
// 修改用户的密码
public boolean upUserPass(int nnid,String pp)
{
this.strSql="update users set ";
this.strSql=this.strSql + "pass=" + "'" + pp + "'";
this.strSql=this.strSql + " where id='" + nnid + "'";
boolean ua = super.exeSql(this.strSql);
return ua;
}
//删除用户
public boolean delUser(long aid)
{
this.strSql="delete from users";
this.strSql=this.strSql + " where id in ("+aid+")";
boolean da = super.exeSql(this.strSql);
return da;
}
//验证登录密码正确
public boolean doLogin(String name,String pass){
this.strSql="select * from users ";
this.strSql=this.strSql + " where name='" + name + "'";
this.strSql=this.strSql + " and pass='"+ pass + "'";
try
{
rs = super.exeSqlQuery(this.strSql);
if (rs.next())
{
int a = rs.getInt(1);
String b = String.valueOf(a);
setId(b);
return true;
}
else
{
return false;
}
}
catch(Exception ex)
{
return false;
}
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -