mysql 2

public class PetDaoImpl extends BaseDao implements PetDao{
 @Override
 public List<Pet> getAllPet() {
  ResultSet rs = this.executeQuery("select * from pet", null);//查询pey表操作
  List<Pet> list = new ArrayList<Pet>();
  try {
   while(rs.next()){
    Pet pet = new Pet();有set和get 方法
    pet.setName(rs.getString("name"));//查询名字pet 类中有。re自带 getstring
    pet.setTypeName(rs.getString("typename"));//查询类型
    list.add(pet);
   }
  } catch (SQLException e) {
   e.printStackTrace();
  }finally{
   this.closeAll(null, null,rs);
  }
  return list;
 }
 @Override
 public List<Pet> selectPet(String sql, String[] param) {
  // TODO Auto-generated method stub
  return null;
 }
 @Overrides
 public int updatePet(String sql, Object[] param) {//定义update方法 。和param数组
//增删查改的操作方法
public int executeSQL(String preparedSql, Object[] param) {
  Connection conn = null;
  PreparedStatement pstmt = null;
  int num = 0;
  /* 处理SQL,执行SQL */
  try {
   conn = getConn(); // 得到数据库连接
   pstmt = conn.prepareStatement(preparedSql); // 得到PreparedStatement对象
   if (param != null) {
    for (int i = 0; i < param.length; i++) {
     pstmt.setObject(i + 1, param[i]); // 为预编译sql设置参数
    }
   }
   // System.out.println(preparedSql);
   num = pstmt.executeUpdate(); // 执行SQL语句
  } catch (ClassNotFoundException e) {
   e.printStackTrace(); // 处理ClassNotFoundException异常
  } catch (SQLException e) {
   e.printStackTrace(); // 处理SQLException异常
  } finally {
   this.closeAll(conn, pstmt, null);
  }
  return num;
 }

  // TODO Auto-generated method stub
  return 0;
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值