DOCX

AdminDba

By Philip Price,2014-12-05 01:57
13 views 0
AdminDbaAdminD

package common;

import java.sql.ResultSet;

    import java.sql.SQLException;

    import java.util.ArrayList;

import entity.Admin;

    import entity.Page;

    public class AdminDba extends BaseDao {

     public ArrayList getAllAdmin() {

     String sql = "select *from admin";

     Object[] o = {};

     return super.getMul(sql, o);

     }

     public int getAdminCount() {// 获取Admin个数

     String sql = "select count(*) from admin";

     Object[] o = {};

     return super.getCount(sql, o);

     }

     public ArrayList getPageAdmin(Page page) {// 获得每一页的Admin

     String sql = "select *from admin order by id limit ?,?";

     Object[] o = { page.getFirstRow(), page.getPageRow() };

     return super.getMul(sql, o);

     }

     public Admin getAdminByLoginName(Admin admin) {// 根据登陆名字获取admin信息

     String sql = "select *from admin where loginName=?";

     Object[] o = { admin.getLoginName() };

     return super.get(sql, o);

     }

     public void deleteAdminByLoginName(Admin admin) {// 根据登陆名字删除admin

     String sql = "delete from admin where loginName=?";

     Object[] o = { admin.getLoginName() };

     try {

     super.save(sql, o);

     } catch (SQLException e) {

     e.printStackTrace();

     }

     }

     public void updateAdminByLoginName(Admin admin) {// 根据登陆名字更改admin

     String sql = "update admin set loginPwd=?,privileges=? where loginName=?";

     Object[] o = { admin.getLoginPwd(), admin.getPrivileges(),

     admin.getLoginName() };

     try {

     super.save(sql, o);

     } catch (SQLException e) {

     e.printStackTrace();

     }

     }

     public void addAdmin(Admin admin){//插入admin

     String sql="insert into admin (loginName,loginPwd,Privileges)values(?,?,?)";

     Object[] o={admin.getLoginName(),admin.getLoginPwd(),admin.getPrivileges()};

     try {

     super.save(sql, o);

     } catch (SQLException e) {

     e.printStackTrace();

     }

     }

     public Admin rowMapper(ResultSet rs) {

     Admin admin = new Admin();

     try {

     admin.setId(rs.getString("id"));

     admin.setLoginName(rs.getString("loginName"));

     admin.setLoginPwd(rs.getString("loginPwd"));

     admin.setPrivileges(rs.getString("privileges"));

     } catch (SQLException e) {

     }

     return admin;

     }

}

Report this document

For any questions or suggestions please email
cust-service@docsford.com