Esempio n. 1
0
 @Override
 public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
   checkCreate(qc);
   try {
     final int id = (int) toLong(exprs[0], qc);
     final JDBCConnections jdbc = jdbc(qc);
     final Object obj = jdbc.get(id);
     if (obj instanceof Connection) {
       ((Connection) obj).close();
     } else {
       ((PreparedStatement) obj).close();
     }
     jdbc.remove(id);
     return null;
   } catch (final SQLException ex) {
     throw BXSQ_ERROR_X.get(info, ex);
   }
 }
Esempio n. 2
0
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    checkCreate(qc);
    // URL to relational database
    final String url = string(toToken(exprs[0], qc));
    final JDBCConnections jdbc = jdbc(qc);
    try {
      if (exprs.length > 2) {
        // credentials
        final String user = string(toToken(exprs[1], qc));
        final String pass = string(toToken(exprs[2], qc));
        if (exprs.length == 4) {
          // connection options
          final Options opts = toOptions(3, Q_OPTIONS, new Options(), qc);
          // extract auto-commit mode from options
          boolean ac = true;
          final HashMap<String, String> options = opts.free();
          final String commit = options.get(AUTO_COMM);
          if (commit != null) {
            ac = Strings.yes(commit);
            options.remove(AUTO_COMM);
          }
          // connection properties
          final Properties props = connProps(options);
          props.setProperty(USER, user);
          props.setProperty(PASS, pass);

          // open connection
          final Connection conn = getConnection(url, props);
          // set auto/commit mode
          conn.setAutoCommit(ac);
          return Int.get(jdbc.add(conn));
        }
        return Int.get(jdbc.add(getConnection(url, user, pass)));
      }
      return Int.get(jdbc.add(getConnection(url)));
    } catch (final SQLException ex) {
      throw BXSQ_ERROR_X.get(info, ex);
    }
  }