关闭

查查

284人阅读 评论(0) 收藏 举报
public class UnisDao {

public void insertUser(UnisVo unisVo)
{
Statement st = null;
Connection conn = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
String sql = "INSERT INTO tableunis (user_name,user_password,user_surepassword,user_sex,user_birth,user_hobby,user_native,user_introduce) VALUES ('"+unisVo.getUserName()+"','"+unisVo.getInputPassword()+"','"+unisVo.getSurePassword()+"','"+unisVo.getUserSex()+"','"+unisVo.getUserYear()+"年"+unisVo.getUserMonth()+"月"+unisVo.getUserDay()+"日"+"','"+unisVo.getUserEnioy()+"','"+unisVo.getProvinceInfo()+unisVo.getCityInfo()+"','"+unisVo.getUserIntroduce()+"')";
//System.out.println(sql);
st.executeUpdate(sql); // 无返回值

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(st, conn);
}
}

public ArrayList selectUser()
{
Statement st = null;
Connection conn = null;
ResultSet rs = null;
ArrayList unisList = new ArrayList();
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
String sql = "SELECT * FROM tableunis WHERE user_display = 1";  
rs = st.executeQuery(sql);
while(rs.next())
{
UnisVo unisVo = new UnisVo();
unisVo.setUserID(rs.getInt("user_id"));
unisVo.setUserName(rs.getString("user_name"));
unisVo.setInputPassword(rs.getString("user_password"));
unisVo.setSurePassword(rs.getString("user_surepassword"));
unisVo.setUserSex(rs.getString("user_sex"));
unisVo.setUserYear(rs.getString("user_birth"));
unisVo.setUserMonth(rs.getString("user_birth"));
unisVo.setUserDay(rs.getString("user_birth"));
unisVo.setUserEnioy(rs.getString("user_hobby"));
unisVo.setProvinceInfo(rs.getString("user_native"));
unisVo.setCityInfo(rs.getString("user_native"));
unisVo.setUserIntroduce(rs.getString("user_introduce"));
unisList.add(unisVo);

}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(rs, st, conn);
}

return unisList;
}

public void deleteUser(String userID)
{
Statement st = null;
Connection conn = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
String sql = "UPDATE tableunis SET user_display = 0 WHERE user_id = '"+userID+"'";
//System.out.println(sql);
st.executeUpdate(sql); // 无返回值

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(st, conn);
}
}

public UnisVo selectOneUser(String userID)
{
Statement st = null;
Connection conn = null;
ResultSet rs = null;
UnisVo unisVo = new UnisVo();
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
String sql = "SELECT * FROM tableunis WHERE user_display = 1 AND user_id = '"+userID+"'";  
rs = st.executeQuery(sql);
while(rs.next())
{

unisVo.setUserID(rs.getInt("user_id"));
unisVo.setUserName(rs.getString("user_name"));
unisVo.setInputPassword(rs.getString("user_password"));
unisVo.setSurePassword(rs.getString("user_surepassword"));
unisVo.setUserSex(rs.getString("user_sex"));
unisVo.setUserYear(rs.getString("user_birth"));
unisVo.setUserMonth(rs.getString("user_birth"));
unisVo.setUserDay(rs.getString("user_birth"));
unisVo.setUserEnioy(rs.getString("user_hobby"));
unisVo.setProvinceInfo(rs.getString("user_native"));
unisVo.setCityInfo(rs.getString("user_native"));
unisVo.setUserIntroduce(rs.getString("user_introduce"));

}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(rs, st, conn);
}

return unisVo;
}

public void deleteUsers(String[] deleteUserIds)
{
Statement st = null;
Connection conn = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
for(int i=0;i<deleteUserIds.length;i++)
{
String sql = "UPDATE tableunis SET user_display = 0 WHERE user_id = '"+deleteUserIds[i]+"'";
//System.out.println(sql);
st.executeUpdate(sql); // 无返回值
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(st, conn);
}
}

public void updateUser(UnisVo unisVo)
{
Statement st = null;
Connection conn = null;
try {
//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");  //加载驱动
//conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=unisdb","sa","sa"); //
conn = DbManage.getConnection();
st = conn.createStatement(); //发送指令集
String sql = "UPDATE tableunis SET user_name = '"+unisVo.getUserName()+"',user_password = '"+unisVo.getInputPassword()+"',user_surepassword = '"+unisVo.getSurePassword()+"',user_sex = '"+unisVo.getUserSex()+"',user_birth='"+unisVo.getUserYear()+"年"+unisVo.getUserMonth()+"月"+unisVo.getUserDay()+"日"+"',user_hobby = '"+unisVo.getUserEnioy()+"',user_native = '"+unisVo.getProvinceInfo()+unisVo.getCityInfo()+"',user_introduce = '"+unisVo.getUserIntroduce()+"' WHERE user_id = '"+unisVo.getUserID()+"'";
//System.out.println(sql);
st.executeUpdate(sql); // 无返回值

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{
DbManage.closeDB(st, conn);
}
}
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9692次
    • 积分:278
    • 等级:
    • 排名:千里之外
    • 原创:18篇
    • 转载:9篇
    • 译文:0篇
    • 评论:0条