package DAO;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import tools.DBHelper;
import entity.User;
public class userDAO {
public List getAllUser(){//查询
String SQL="select * from user";
ResultSet rs=DBHelper.getResultSet(SQL);
return tools.tools.resultSetToList(rs, User.class);
}
public static boolean add(User u)//添加数据
{
String sql="INSERT INTO user(userID,userName,password) "+"VALUES(?,?,?)";
Object[] params=new Object[]{u.getUserID(),u.getUserName(),u.getPassword()};
int n=DBHelper.ExecSql(sql, params);
if(n>0)
return true;
else
return false;
}
public static boolean delete(User u)//删除数据
{
String sql="DELETE FROM user WHERE userID=?";
Object[] params=new Object[]{u.getUserID()};
int n=DBHelper.ExecSql(sql, params);
if(n>0)
return true;
else
return false;
}
public static boolean update(User u)//修改数据
{
String sql="update user set userName=?,password=? where userID=?";
Object[] params=new Object[]{u.getUserName(), u.getPassword(), u.getUserID()};
int n=DBHelper.ExecSql(sql, params);
if(n>0)
return true;
else
return false;
}
}