我这样执行了3条delete,有什么好办法判断哪些执行了
我就会写一堆if else,有没有更好的办法?
int flag = 0;
int flagip = 0;
int flagw = 0;
if (null != ispId && !ispId.equals("")) {
Connection conn = IpareaDBPool.getInstance().getConnection();
String sql = "delete from isp where id=?";
String sqlip = "delete from ip where isp_id=?";
String sqlw = "delete from weight where isp_id=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sqlip);
pstmt.setInt(1, Integer.parseInt(ispId));
flagip = pstmt.executeUpdate(); pstmt = conn.prepareStatement(sqlw);
pstmt.setInt(1, Integer.parseInt(ispId));
flagw = pstmt.executeUpdate(); pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, Integer.parseInt(ispId));
flag = pstmt.executeUpdate();
我就会写一堆if else,有没有更好的办法?
int flag = 0;
int flagip = 0;
int flagw = 0;
if (null != ispId && !ispId.equals("")) {
Connection conn = IpareaDBPool.getInstance().getConnection();
String sql = "delete from isp where id=?";
String sqlip = "delete from ip where isp_id=?";
String sqlw = "delete from weight where isp_id=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = conn.prepareStatement(sqlip);
pstmt.setInt(1, Integer.parseInt(ispId));
flagip = pstmt.executeUpdate(); pstmt = conn.prepareStatement(sqlw);
pstmt.setInt(1, Integer.parseInt(ispId));
flagw = pstmt.executeUpdate(); pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, Integer.parseInt(ispId));
flag = pstmt.executeUpdate();
int flagip = 0;
int flagw = 0;
你上面定义了这三个变量用来存储执行后返回的受影响的行数如果Id存在且数据库有数据那么这个三个变量返回得到的数一定不是0 如果为0 你就要看看Id是否有值,数据库是否有数据.