Java代码

public int addReview(Review review) {
Connection conn=null; //创建连接对象
PreparedStatement pstmt=null; //创建执行对象
//ResultSet rs=null;
int result=0;
String sql="insert into nrs_review (r_content,r_username,r_revtime,n_id) values(?,?,?,?)";

try {
conn=DBUtil.getConn(); //得到连接
pstmt=conn.prepareStatement(sql); //得到执行对象
//执行插入操作
pstmt.setString(1,review.getR_content());
pstmt.setString(2,review.getR_username());
pstmt.setString(3,review.getR_revtime());
pstmt.setInt(4,review.getN_id());
result=pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}finally{
//关闭连接
DBUtil.closeStatement(pstmt);
DBUtil.closeConn(conn);

}
return result;
}

猜你喜欢

转载自lakers-com.iteye.com/blog/2248615