增、删、改、查
2016-08-04 01:52
309 查看
public int doAdd(Reply reply) {
String sql = "insert into reply values(null,?,?,?,?,?,?)";
return this.getJdbc().executeUpdate(
sql,
new String[] { reply.getTitle(), reply.getContent(),
reply.getPublishtime().toString(),
reply.getModifytime().toString(),
reply.getTopicid() + "", reply.getUid() + "" });
}
------------------------------------------------------------------------------------------------
public int doDelete(String replyid) {
String sql = "delete from reply where replyid=" + replyid;
return this.getJdbc().executeUpdate(sql, null);
}
---------------------------------------------------------------------------------------------------
public List<Board> findAll(){
List<Board> list=new ArrayList<Board>();
//创建sql语句
String sql="select * from board";
//执行查询
ResultSet rs=this.getJdbc().executeQuery(sql, null);
//遍历
try {
while(rs.next()){
Board board=new Board();
board.setBoardid(rs.getInt("boardid"));
board.setBoardname(rs.getString("boardname"));
list.add(board);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeResource();
}
return list;
}
--------------------------------------------------------------------------------------------------
public int doUpdate(Reply reply) {
String sql = "update reply set title = ?, content = ?, modifytime = ? where replyid = ?";
return this.getJdbc().executeUpdate(sql, new String[] { reply.getTitle(), reply.getContent(),
reply.getModifytime().toString(), reply.getReplyid() + "" });
}
String sql = "insert into reply values(null,?,?,?,?,?,?)";
return this.getJdbc().executeUpdate(
sql,
new String[] { reply.getTitle(), reply.getContent(),
reply.getPublishtime().toString(),
reply.getModifytime().toString(),
reply.getTopicid() + "", reply.getUid() + "" });
}
------------------------------------------------------------------------------------------------
public int doDelete(String replyid) {
String sql = "delete from reply where replyid=" + replyid;
return this.getJdbc().executeUpdate(sql, null);
}
---------------------------------------------------------------------------------------------------
public List<Board> findAll(){
List<Board> list=new ArrayList<Board>();
//创建sql语句
String sql="select * from board";
//执行查询
ResultSet rs=this.getJdbc().executeQuery(sql, null);
//遍历
try {
while(rs.next()){
Board board=new Board();
board.setBoardid(rs.getInt("boardid"));
board.setBoardname(rs.getString("boardname"));
list.add(board);
}
} catch (SQLException e) {
e.printStackTrace();
}finally{
this.closeResource();
}
return list;
}
--------------------------------------------------------------------------------------------------
public int doUpdate(Reply reply) {
String sql = "update reply set title = ?, content = ?, modifytime = ? where replyid = ?";
return this.getJdbc().executeUpdate(sql, new String[] { reply.getTitle(), reply.getContent(),
reply.getModifytime().toString(), reply.getReplyid() + "" });
}
相关文章推荐
- [React Native + Firebase] React Native: Real time database with Firebase -- setup & CRUD
- 路由选择RIP协议解析
- Servlet(1)
- 地图定位
- Swift 语言面面观(二)
- 51Nod-1315-合法整数集
- Swift 语言面面观(一)
- 使用 Swift 创建简单的二维码扫描应用
- IntelliJ IDEA 常用设置讲解3
- webpack(二)配置
- Objective-C isa 指针 与 runtime 机制
- just a test
- Centos 7 下LAMP环境调试搭配(+phpmyadmin+phpstorm)
- Swift 3 新特性
- Android Studio安装MonkeyTalk Agent小记
- Installing Powerline on OS X + homebrew
- 小幸运
- 基于RelativeLayout实现自动换行标签控件
- android视图动画、属性动画、自定义动画、5.X SVG矢量动画机制详解
- IntelliJ IDEA 常用设置讲解2