mysql 2
来源:互联网 发布:新开淘宝店卖什么好 编辑:程序博客网 时间:2024/06/10 14:19
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;
}
0 0
- Mysql(2)
- MySQL(2)
- MySQL (2)
- mysql 2
- mysql(2)
- [2]-Mysql
- mysql 2
- 2、MYSQL
- mysql (2)
- MySQL必知必会-2安装MySQL
- MySQL解析(2)--MySQL版本
- mysql笔记-- mysql命令札记2
- MySQL学习笔记(2)MySQL高级
- mysql基础2【常用mysql语句】
- mysql学习笔记(2)-创建MySQL索引
- MySQL学习【2】MySQL命令行操作
- mysql数据库入门(2)--mysql安装
- MYSQL学习心得(2) --使用MySQL的LAST_INSERT_ID
- Spring Boot学习笔记(零) 前言
- Search a 2D Matrix
- 357. Count Numbers with Unique Digits
- HDU 5818 Joint Stacks 栈模拟
- httpclientget网络请求数据
- mysql 2
- 双系统Ubuntu无法访问windows磁盘分区解决方法
- 自定义两个圆环一直转
- leetcode 338 Counting Bits
- Java反射基础
- Jquery相关层次选择器
- 四连通与八连通
- yii查询相关
- 坚持#第178天~录屏是个双倍神符,学知识超快,能够提升自己、别忘了学以致用,有什么好害羞的!