首页>代码>jsp+servlet开发java web诚欣企业电子商城(源码+数据库脚本)>/企业电子商城/Shopping/src/com/wy/dao/ManagerDao.java
package com.wy.dao;

import java.sql.*;
import java.util.*;
import com.wy.domain.ManagerForm;
import com.wy.tool.JDBConnection;

//对管理员的操作
public class ManagerDao {
  private Connection connection = null; //定义连接的对象
  private PreparedStatement ps = null; //定义预准备的对象
  private JDBConnection jdbc = null; //定义数据库连接对象
  public ManagerDao() {
    jdbc = new JDBConnection();
    connection = jdbc.connection; //利用构造方法取得数据库连接
  }

  //对管理员表的查询方法
  public void insertManager(ManagerForm form) {
    try {

      ps = connection.prepareStatement("insert into tb_manager values (null,?,?,?,?)");
      ps.setString(1, form.getAccount());
      ps.setString(2, form.getPassword());
      ps.setString(3, form.getName());
      ps.setInt(4, 0);
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    	ex.printStackTrace();
    }
  }

  //修改管理员密码的方法
  public void updateManagerPassword(ManagerForm form) {
    try {
      ps = connection.prepareStatement("update tb_manager set password=? where account=?");
      ps.setString(1, form.getPassword());
      ps.setString(2,form.getAccount());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    	ex.printStackTrace();
    }
  }


  //删除管理员的操作
  public void deleteManager(Integer id) {
    try {
      ps = connection.prepareStatement("delete from tb_manager where id=?");
      ps.setInt(1, id.intValue());
      ps.executeUpdate();
      ps.close();
    }
    catch (SQLException ex) {
    	ex.printStackTrace();
    }
  }

  //查询全部管理员的信息
  public List selectManager() {
    List list = new ArrayList();
    ManagerForm manager = null;
    try {
      ps = connection.prepareStatement("select * from tb_manager order by id DESC");
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        manager = new ManagerForm();
        manager.setId(Integer.valueOf(rs.getString(1)));
        manager.setAccount(rs.getString(2));
        manager.setPassword(rs.getString(3));
        manager.setName(rs.getString(4));
        manager.setSigh(Integer.valueOf(rs.getString(5)));
        list.add(manager);
      }
    }
    catch (SQLException ex) {
    	ex.printStackTrace();
    }
    return list;
  }

//以管理员账号为条件查询管理员信息
  public ManagerForm selectOne(String account) {
    ManagerForm manager = null;
    try {
      ps = connection.prepareStatement("select * from tb_manager where account=?");
      ps.setString(1, account);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        manager = new ManagerForm();
        manager.setId(Integer.valueOf(rs.getString(1)));
        manager.setAccount(rs.getString(2));
        manager.setPassword(rs.getString(3));
        manager.setName(rs.getString(4));
        manager.setSigh(Integer.valueOf(rs.getString(5)));
      }
    }
    catch (SQLException ex) {
    	ex.printStackTrace();
    }
    return manager;
  }



}
最近下载更多
微信网友_6790966844739584  LV5 2024年6月12日
LYLHYC  LV5 2023年8月2日
一勺枣糕  LV3 2023年7月5日
微信网友_6518834447732736  LV1 2023年6月14日
846488283  LV4 2023年5月31日
西域行者  LV3 2023年4月24日
qiuaizhang  LV3 2023年4月10日
1762806977  LV4 2023年3月15日
阿达asdw1  LV4 2023年3月13日
微信网友_6008098523172864  LV3 2023年3月8日
最近浏览更多
lala12345 6月22日
暂无贡献等级
暂无贡献等级
歪比歪比 5月27日
暂无贡献等级
李玟龙  LV2 5月13日
wwy000  LV2 4月29日
biakuya  LV2 1月4日
wzd031105  LV2 2024年12月7日
zolscy  LV24 2024年11月28日
kfq33122  LV4 2024年11月13日
张泽帅  LV6 2024年10月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友