java 删除数据

来源:百度知道 编辑:UC知道 时间:2024/06/09 01:21:37
我想根据id删除一条某表的信息,比如根据人员编号删除这个人员的信息。
String sql ="delete from person where personid =?";
conn = db.getConn();//打开数据库连接
下面怎么写?
ps = .......
用preparedstatment. (ps表示)
这个方法是返回boolean的。
这一块怎么写 ?
*************
id是传过来的 .这个我知道.
就是下面的那块怎么写 ?
用不用得着ResultSet了?我要求返回一个boolean值。

public boolean DetStuInfo(Integer stuId) {
boolean result=false;
Connection con=null;
PreparedStatement pstmt=null;
try {
con=StudentUtil.getConnection();
String sql="DELETE FROM StudentDB WHERE stuId=?";
pstmt=con.prepareStatement(sql);
pstmt.setInt(1,stuId);
pstmt.executeUpdate();
result=true;
} catch (SQLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} finally
{
StudentUtil.closePreparedStatement(pstmt);
StudentUtil.closeConnecion(con);
}
return result;
}

时间问题!不给你写了!给你例子你!相信你能看懂的!不明白再问我!

String id="xxx"
String sql ="delete from person where personid ="+id;