コード例 #1
0
  public static Object[][] Query(Object[] s) {
    Object[][] obj = (Object[][]) null;
    StringBuffer sb = new StringBuffer("SELECT * FROM Purchase WHERE ");
    boolean b = false;
    if (s[0] != "") {
      sb.append("drug_id = '" + s[0] + "'");
      b = true;
    }
    if (s[1] != "") {
      if (b) sb.append(" AND ");
      sb.append("batch_num = '" + s[1] + "'");
      b = true;
    }
    if (s[2] != null) {
      if (b) sb.append(" AND ");
      sb.append("vali_date < #" + s[2] + "#");
      b = true;
    }
    if (s[3] != null) {
      if (b) sb.append(" AND ");
      sb.append("pur_date < #" + s[3] + "#");
    }
    String sql_query = new String(sb);
    try {
      Connection conn = DriverManager.getConnection(url, "", "");
      Statement sql = conn.createStatement(1004, 1007);

      ResultSet rs = sql.executeQuery(sql_query);
      rs.last();
      int n = rs.getRow();
      rs.beforeFirst();
      obj = new Object[n][8];
      int i = 0;
      while (rs.next()) {
        for (int j = 1; j <= 8; j++) {
          if (j == 2) obj[i][(j - 1)] = DrugSQL.getDrugname(rs.getString(j));
          else if ((j == 4) || (j == 8)) obj[i][(j - 1)] = rs.getDate(j);
          else obj[i][(j - 1)] = rs.getObject(j);
        }
        i++;
      }
      conn.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return obj;
  }
コード例 #2
0
  public static Object[] getRecord(String id) {
    Object[] object = new Object[8];
    try {
      Connection conn = DriverManager.getConnection(url, "", "");
      PreparedStatement sql = conn.prepareStatement("SELECT * FROM Purchase WHERE pur_id = ?");

      sql.setString(1, id);
      ResultSet rs = sql.executeQuery();
      int j = 1;
      while (rs.next()) {
        if (j == 2) object[(j - 1)] = DrugSQL.getDrugname(rs.getString(j));
        else if ((j == 4) || (j == 8)) object[(j - 1)] = rs.getDate(j);
        else object[(j - 1)] = rs.getObject(j);
        j++;
      }

      conn.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return object;
  }
コード例 #3
0
  public static Object[][] getAll() {
    int n = CountRecord();
    Object[][] obj = new Object[n][8];
    try {
      Connection conn = DriverManager.getConnection(url, "", "");
      Statement sql = conn.createStatement();

      ResultSet rs = sql.executeQuery("SELECT * FROM Purchase");
      int i = 0;
      while (rs.next()) {
        for (int j = 1; j <= 8; j++) {
          if (j == 2) obj[i][(j - 1)] = DrugSQL.getDrugname(rs.getString(j));
          else if ((j == 4) || (j == 8)) obj[i][(j - 1)] = rs.getDate(j);
          else obj[i][(j - 1)] = rs.getObject(j);
        }
        i++;
      }
      conn.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return obj;
  }