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;
}
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;
}
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 updatePet(String sql, Object[] param) {//定义update方法 。和param数组
//增删查改的操作方法
public int executeSQL(String preparedSql, Object[] param) {
Connection conn = null;
PreparedStatement pstmt = null;
int num = 0;
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;
}
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;
}