public static int save(DBConnect dbc, TbConProvince tbconprovince) throws Exception { int result = EXECUTE_FAIL; String sql = "insert into tb_con_province(`pid`,`pname`) values(?,?)"; dbc.prepareStatement(sql); dbc.setInt(1, tbconprovince.getPid()); dbc.setString(2, tbconprovince.getPname()); dbc.executeUpdate(); result = EXECUTE_SUCCESSS; return result; }
public static int update(DBConnect dbc, TbConProvince tbconprovince) throws Exception { int result = EXECUTE_FAIL; StringBuffer sb = new StringBuffer(); sb.append("update tb_con_province set "); boolean flag = false; if (tbconprovince.COLUMN_FLAG[0]) { if (flag) { sb.append(",pid=?"); } else { sb.append("pid=?"); flag = true; } } if (tbconprovince.COLUMN_FLAG[1]) { if (flag) { sb.append(",pname=?"); } else { sb.append("pname=?"); flag = true; } } sb.append(" where pid=?"); dbc = new DBConnect(); dbc.prepareStatement(sb.toString()); int k = 1; if (tbconprovince.COLUMN_FLAG[0]) { dbc.setInt(k, tbconprovince.getPid()); k++; } if (tbconprovince.COLUMN_FLAG[1]) { dbc.setString(k, tbconprovince.getPname()); k++; } dbc.setInt(k, tbconprovince.getPid()); dbc.executeUpdate(); dbc.close(); result = EXECUTE_SUCCESSS; return result; }
public static void fill(ResultSet rs, TbConProvince tbconprovince) throws SQLException { tbconprovince.setPid(rs.getInt("pid")); // 自增长主键 省列表 tbconprovince.setPname(rs.getString("pname")); // }