catch (Exception ex) { ex.printStackTrace(); throw new DBAccessException(InforGeter.getErrorInfor(this, "putRow", ex, "更新表" + name + "中的数据时出错!")); } finally { database.disConnect(conn); } return affectableRow; } /** * 删除一行 * @param row */ public int delRow(Row row) throws DBAccessException { String ss = ""; int affectableRow = 0; ss = "delete from " + name + " where "; for (int i = 0; i < row.length(); ++i) { String k = row.getKey(i); ss += k + ((row.get(i) == null)?" is null":"=?"); //设置查询参数有空值处理 if (i != row.length() - 1) { ss += " and "; } } Connection conn = null; try { conn = database.getConnection(); PreparedStatement st = conn.prepareStatement(ss); int j = 0;//查询参数计数器 for (int i = 0; i < row.length(); i++) { if (row.get(i) != null) { st.setObject(++j, row.get(i)); //解析查询参数 } } affectableRow = st.executeUpdate(); st.close(); } catch (Exception ex) { throw new DBAccessException(InforGeter.getErrorInfor(this, "delRow", ex, "删除表" + name + "中的数据时出错!")); } finally { database.disConnect(conn); } return affectableRow; } |