您的位置:首页 > 其它

增、删、改、查

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() + "" });
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: