SysManagerDao

package com.gs.stu.dao.impl;


import java.sql.*;
import java.util.ArrayList;
import java.util.List;


import com.gs.stu.bean.Manager;
import com.gs.stu.dao.SysManagerDao;
import com.gs.stu.util.DBConnection;


public class SysManagerDaoImpl implements SysManagerDao{
//根据管理员帐号和密码查询管理员
public Manager managerLogin(String sysaccount, String syspassword) {
Manager m = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;//查询返回结果集
String sql = "select * from t_manager where sysaccount=? and syspassword=?";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setString(1, sysaccount);
pstmt.setString(2, syspassword);
//4.执行
rs = pstmt.executeQuery();
//遍历rs
while (rs.next()) {
m = new Manager();
m.setId(rs.getInt(1));
m.setSysaccount(rs.getString(2));
m.setSyspassword(rs.getString(3));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return m;
}
//添加管理员
public int addManager(Manager m) {
Connection conn = null;
PreparedStatement pstmt = null;
int row = 0;
String sql = "insert into t_manager values(?,?)";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setString(1, m.getSysaccount());
pstmt.setString(2, m.getSyspassword());
//4.执行
row = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return row;
}
//删除管理员
public int deleteManager(int id) {
Connection conn = null;
PreparedStatement pstmt = null;
int row = 0;
String sql = "delete t_manager where id=?";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setInt(1, id);
//4.执行
row = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return row;
}
//修改管理员密码
public int updateManager(Manager m) {
Connection conn = null;
PreparedStatement pstmt = null;
int row = 0;
String sql = "update t_manager set syspassword=? where sysaccount=?";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setString(1, m.getSyspassword());
pstmt.setString(2, m.getSysaccount());
//4.执行
row = pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return row;
}
//根据id查询管理员
public Manager findManagerById(int id) {
Manager m = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;//查询返回结果集
String sql = "select * from t_manager where id=?";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setInt(1, id);
//4.执行
rs = pstmt.executeQuery();
//遍历rs
if (rs.next()) {
m = new Manager();
m.setId(rs.getInt(1));
m.setSysaccount(rs.getString(2));
m.setSyspassword(rs.getString(3));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return m;
}
//根据管理员帐号查询管理员
public Manager findManagerByAccount(String sysaccount) {
Manager m = null;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;//查询返回结果集
String sql = "select * from t_manager where sysaccount=?";
try {
//1.创建连接
conn = DBConnection.getConnection();
//2.创建执行对象
pstmt = conn.prepareStatement(sql);
//3.给参数赋值
pstmt.setString(1, sysaccount);
//4.执行
rs = pstmt.executeQuery();
//遍历rs
if (rs.next()) {
m = new Manager();
m.setId(rs.getInt(1));
m.setSysaccount(rs.getString(2));
m.setSyspassword(rs.getString(3));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return m;
}
//查询所有管理员信息
public List<Manager> findAllManager() {
List<Manager> list = new ArrayList<Manager>();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;//查询返回结果集
String sql = "select * from t_manager";
try {
conn = DBConnection.getConnection();
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
//遍历rs
while (rs.next()) {
Manager m = new Manager();
m.setId(rs.getInt(1));
m.setSysaccount(rs.getString(2));
m.setSyspassword(rs.getString(3));
list.add(m);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
DBConnection.closeResultSet(rs);
DBConnection.closeStatement(pstmt);
DBConnection.closeConn(conn);
}
return list;
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值