Пример #1
0
 private String buildInsertStatement() {
   StringBuilder sql = new StringBuilder();
   sql.append("insert into ").append(into.name());
   sql.append("(").append(JDBC.asString(into.columnNames())).append(")");
   sql.append(" values(").append(JDBC.asString(parametersFor(into.columnNames()))).append(")");
   return sql.toString();
 }
Пример #2
0
  private void find_query(
      Connection conn, String arg, ArrayList<?> attr, String col1, String col2, String table)
      throws SQLException {
    ResultSet rs;
    Statement st;
    ArrayList<String> al = new ArrayList<String>();
    if (col2.equals("ActionName") || col2.equals("ArtifactName")) {

      String query =
          "Select "
              + col2
              + " from "
              + conn.getCatalog()
              + "."
              + table
              + " where  "
              + col1
              + "  like  "
              + "'"
              + arg
              + "%' ";
      // System.out.println(query);
      st = conn.createStatement();
      rs = st.executeQuery(query);
      al = JDBC.resultSet2String(rs, col2);
      convert_string(attr, col1, al);
    } else {
      String query =
          "Select "
              + col2
              + " from "
              + conn.getCatalog()
              + "."
              + table
              + " where "
              + col1
              + "="
              + "'"
              + arg
              + "'";
      // System.out.println(query);
      st = conn.createStatement();
      rs = st.executeQuery(query);
      al = JDBC.resultSet2String(rs, col2);
      convert_string(attr, col2, al);
    }
  }
Пример #3
0
  /**
   * Decorate a set of tests to use an encrypted single use database. This is to run tests using
   * encryption as a general test and not specific tests of how encryption is handled. E.g. tests of
   * setting various URL attributes would be handled in a specific test. <br>
   * The database will use the default encryption algorithm.
   *
   * @param test test to decorate
   * @param bootPassword boot passphrase to use
   * @return decorated tests
   */
  public static Test encryptedDatabaseBpw(Test test, String bootPassword) {
    if (JDBC.vmSupportsJSR169()) return new TestSuite("no encryption support");

    Properties attributes = new Properties();
    attributes.setProperty("dataEncryption", "true");
    attributes.setProperty("bootPassword", bootPassword);

    return attributesDatabase(attributes, test);
  }
  public int introducirEnBD() {
    int rowsAffected = 0;
    JDBC dbConnection = new JDBC();

    String sql =
        "INSERT INTO placa (FechaCompra, TipoPlacaID)"
            + "VALUES ('"
            + fechaCompra
            + "', '"
            + tipoPlacaID
            + "');";

    System.out.println(sql);

    rowsAffected = dbConnection.ejecutarUpdate(sql);
    System.out.println("FilasAfectadas: " + rowsAffected);

    return rowsAffected;
  }
Пример #5
0
  /** Returns true if the derby client is available to the tests. */
  public static boolean hasClient() {
    // classes folder - assume all is available.
    if (!SecurityManagerSetup.isJars) return true;

    // if we attempt to check on availability of the ClientDataSource with
    // JSR169, attempts will be made to load classes not supported in
    // that environment, such as javax.naming.Referenceable. See DERBY-2269.
    if (!JDBC.vmSupportsJSR169()) {
      return hasCorrectJar("/derbyclient.jar", "org.apache.derby.jdbc.ClientDataSource");
    } else return false;
  }
Пример #6
0
 public void execute(final Connection connection) {
   PreparedStatement insert = null;
   try {
     insert = connection.prepareStatement(buildInsertStatement(), RETURN_GENERATED_KEYS);
     into.dehydrate(insert, entity);
     executeInsert(insert);
     into.handleKeys(insert.getGeneratedKeys(), entity);
   } catch (SQLException e) {
     throw new JDBCException("Could not insert entity " + entity, e);
   } finally {
     JDBC.close(insert);
   }
 }
  public int introducirEnBD() {
    int rowsAffected = 0;
    JDBC dbConnection = new JDBC();

    String sql =
        "INSERT INTO comedero (ComederoID, Descripcion, ModeloID, EstacionID) "
            + "VALUES ('"
            + comederoID
            + "','"
            + descripcion
            + "','"
            + modeloID
            + "','"
            + estacionID
            + "');";

    System.out.println(sql);
    rowsAffected = dbConnection.ejecutarUpdate(sql);
    System.out.println("FilasAfectadas: " + rowsAffected);

    return rowsAffected;
  }
Пример #8
0
  public static void main(String[] args) {
    int anzVersuche = 100000;
    Patch p = new Patch();
    Karte[] karten = new Karte[52];
    Karte[] hand = new Karte[5];
    Methoden m = new Methoden();
    JDBC j = new JDBC();
    int pz = 0, dpz = 0, fhz = 0, poz = 0, flz = 0, sz = 0, sfz = 0, rfz = 0, dz = 0;

    for (int i = 0; i < anzVersuche; i++) {

      karten = p.kartenErzeugen();

      hand = p.handSuchen(karten);

      switch (m.ParrDrillingPoker(hand)) {
          // paar
        case (1):
          pz++;
          break;
          // zwei paare
        case (2):
          dpz++;
          break;
          // drilling
        case (3):
          dz++;
          break;
          // poker
        case (4):
          poz++;
          break;
          // fullhouse
        case (5):
          fhz++;
          break;
      }

      if ((m.IstFlush(hand) == true) && (m.Straße(hand) == false)) {
        flz++;
      }
      if ((m.IstFlush(hand) == true) && (m.Straße(hand) == true)) {
        sfz++;
      }
      if ((m.IstFlush(hand) == false) && (m.Straße(hand) == true)) {
        sz++;
      }
      if ((m.Royal(hand) == true) && (m.IstFlush(hand) == true)) {
        rfz++;
      }
    }

    paar = pz;
    doppelpaar = dpz;
    drilling = dz;
    poker = poz;
    fullhouse = fhz;
    flush = flz;
    straße = sz;
    straightFlush = sfz;
    roylflush = rfz;
    highkart =
        anzVersuche
            - paar
            - doppelpaar
            - drilling
            - poker
            - fullhouse
            - flush
            - straße
            - straightFlush
            - roylflush;
    j.dadenbankErzeugen();
    j.tableErzeugen();
    j.insertTable();
    // j.drop();
    j.select();
  }
 /** @see javax.sql.DataSource#getConnection(java.lang.String, java.lang.String) */
 public Connection getConnection(String username, String password) throws SQLException {
   Properties p = config.toProperties();
   if (username != null) p.put("user", username);
   if (password != null) p.put("pass", password);
   return JDBC.createConnection(url, p);
 }