【发布时间】:2019-04-11 08:11:25
【问题描述】:
'我想在删除任何行时重新组织和重新排序行。” 例如:如果我删除 id=5 的行,则第 6 个 id 的行应更改为 5。
Java jsp 和 mysql 在 netbeans 上使用。
编辑方法:
public void edit(int id, String title, String description, String detail, String category, String image){
String sql = "update News set title = ?, description=?, Details=?, category=?, image=?" + " where id=? ";
PreparedStatement ps;
try {
ps = DBUtils.getPreparedStatement(sql);
ps.setString(1,title);
ps.setString(2,description );
ps.setString(3,detail);
ps.setString(4,category );
ps.setString(5,image);
ps.setInt(6,id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
删除方法:
public void delete(int id){
try {
String sql = "delete from News where id = ?";
PreparedStatement ps = DBUtils.getPreparedStatement(sql);
ps.setInt(1, id);
ps.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
}
}
【问题讨论】: