Example usage for java.sql ResultSet CONCUR_READ_ONLY

List of usage examples for java.sql ResultSet CONCUR_READ_ONLY

Introduction

In this page you can find the example usage for java.sql ResultSet CONCUR_READ_ONLY.

Prototype

int CONCUR_READ_ONLY

To view the source code for java.sql ResultSet CONCUR_READ_ONLY.

Click Source Link

Document

The constant indicating the concurrency mode for a ResultSet object that may NOT be updated.

Usage

From source file:com.btobits.automator.ant.sql.task.SQLCompareTask.java

@Override
public void execute() throws BuildException {
    validateParameter();//from   w ww .  j ava2s  . co  m

    Connection cnn = null;
    try {
        Class.forName(driver);
        cnn = DriverManager.getConnection(url, user, password);
        final Statement stmt = cnn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        resultSet = stmt.executeQuery(query);

        verify();

    } catch (Exception ex) {
        resultSet = null;
        throw new BuildException("Error build: " + ex.getMessage());
    } finally {
        try {
            cnn.close();
        } catch (Exception ex) {
        }
    }

    if (errors.size() > 0) {
        throw new BuildException(toString(errors));
    }
}

From source file:com.cloudera.sqoop.manager.NetezzaImportManualTest.java

private void createTable(String tableName, String... extraColumns) throws SQLException {
    PreparedStatement statement = conn.prepareStatement("DROP TABLE " + tableName, ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    try {/*from  w ww .ja v  a 2s  . c  om*/
        statement.executeUpdate();
        conn.commit();
    } catch (SQLException sqle) {
        conn.rollback();
    } finally {
        statement.close();
    }

    StringBuilder sb = new StringBuilder();
    sb.append("CREATE TABLE " + tableName + " (");
    sb.append("id INT NOT NULL PRIMARY KEY, ");
    sb.append("name VARCHAR(24) NOT NULL, ");
    sb.append("start_date DATE, ");
    sb.append("Salary FLOAT, ");
    sb.append("Fired BOOL, ");
    sb.append("dept VARCHAR(32) ");
    for (String col : extraColumns) {
        sb.append(", " + col + "  INTEGER");
    }
    sb.append(")");

    statement = conn.prepareStatement(sb.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
    try {
        statement.executeUpdate();
        conn.commit();
    } finally {
        statement.close();
    }
}

From source file:eu.stratosphere.api.java.io.jdbc.JDBCInputFormat.java

/**
 * Connects to the source database and executes the query.
 *
 * @param ignored/*  www .j  av  a  2s .  c o  m*/
 * @throws IOException
 */
@Override
public void open(InputSplit ignored) throws IOException {
    try {
        establishConnection();
        statement = dbConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        resultSet = statement.executeQuery(query);
    } catch (SQLException se) {
        close();
        throw new IllegalArgumentException("open() failed." + se.getMessage(), se);
    } catch (ClassNotFoundException cnfe) {
        throw new IllegalArgumentException("JDBC-Class not found. - " + cnfe.getMessage(), cnfe);
    }
}

From source file:org.owasp.webgoat.plugin.CrossSiteScriptingLesson6a.java

protected AttackResult injectableQuery(String accountName) {
    try {//from   ww w.j  a  va 2s  .c o  m
        Connection connection = DatabaseUtilities.getConnection(getWebSession());
        String query = "SELECT * FROM user_data WHERE last_name = '" + accountName + "'";

        try {
            Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY);
            ResultSet results = statement.executeQuery(query);

            if ((results != null) && (results.first() == true)) {
                ResultSetMetaData resultsMetaData = results.getMetaData();
                StringBuffer output = new StringBuffer();

                output.append(writeTable(results, resultsMetaData));
                results.last();

                // If they get back more than one user they succeeded
                if (results.getRow() >= 6) {
                    return trackProgress(AttackResult.success("You have succeed: " + output.toString()));
                } else {
                    return trackProgress(AttackResult.failed("You are close, try again. " + output.toString()));
                }

            } else {
                return trackProgress(AttackResult.failed("No Results Matched. Try Again. "));

            }
        } catch (SQLException sqle) {

            return trackProgress(AttackResult.failed(sqle.getMessage()));
        }
    } catch (Exception e) {
        e.printStackTrace();
        return trackProgress(
                AttackResult.failed("ErrorGenerating" + this.getClass().getName() + " : " + e.getMessage()));
    }
}

From source file:co.nubetech.apache.hadoop.DBRecordReader.java

protected ResultSet executeQuery(String query) throws SQLException {
    this.statement = connection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    return statement.executeQuery();
}

From source file:com.opensoc.enrichment.adapters.geo.GeoMysqlAdapter.java

@SuppressWarnings("unchecked")
@Override/*  w  w w .  j av a  2  s  .c  om*/
public JSONObject enrich(String metadata) {

    ResultSet resultSet = null;

    try {

        _LOG.trace("[OpenSOC] Received metadata: " + metadata);

        InetAddress addr = InetAddress.getByName(metadata);

        if (addr.isAnyLocalAddress() || addr.isLoopbackAddress() || addr.isSiteLocalAddress()
                || addr.isMulticastAddress() || !ipvalidator.isValidInet4Address(metadata)) {
            _LOG.trace("[OpenSOC] Not a remote IP: " + metadata);
            _LOG.trace("[OpenSOC] Returning enrichment: " + "{}");

            return new JSONObject();
        }

        _LOG.trace("[OpenSOC] Is a valid remote IP: " + metadata);

        statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String locid_query = "select IPTOLOCID(\"" + metadata + "\") as ANS";
        resultSet = statement.executeQuery(locid_query);

        if (resultSet == null)
            throw new Exception(
                    "Invalid result set for metadata: " + metadata + ". Query run was: " + locid_query);

        resultSet.last();
        int size = resultSet.getRow();

        if (size == 0)
            throw new Exception("No result returned for: " + metadata + ". Query run was: " + locid_query);

        resultSet.beforeFirst();
        resultSet.next();

        String locid = null;
        locid = resultSet.getString("ANS");

        if (locid == null)
            throw new Exception("Invalid location id for: " + metadata + ". Query run was: " + locid_query);

        String geo_query = "select * from location where locID = " + locid + ";";
        resultSet = statement.executeQuery(geo_query);

        if (resultSet == null)
            throw new Exception("Invalid result set for metadata and locid: " + metadata + ", " + locid
                    + ". Query run was: " + geo_query);

        resultSet.last();
        size = resultSet.getRow();

        if (size == 0)
            throw new Exception("No result id returned for metadata and locid: " + metadata + ", " + locid
                    + ". Query run was: " + geo_query);

        resultSet.beforeFirst();
        resultSet.next();

        JSONObject jo = new JSONObject();
        jo.put("locID", resultSet.getString("locID"));
        jo.put("country", resultSet.getString("country"));
        jo.put("city", resultSet.getString("city"));
        jo.put("postalCode", resultSet.getString("postalCode"));
        jo.put("latitude", resultSet.getString("latitude"));
        jo.put("longitude", resultSet.getString("longitude"));
        jo.put("dmaCode", resultSet.getString("dmaCode"));
        jo.put("locID", resultSet.getString("locID"));

        jo.put("location_point", jo.get("longitude") + "," + jo.get("latitude"));

        _LOG.debug("Returning enrichment: " + jo);

        return jo;

    } catch (Exception e) {
        e.printStackTrace();
        _LOG.error("Enrichment failure: " + e);
        return new JSONObject();
    }
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

CassandraStatement(CassandraConnection con) throws SQLException {
    this(con, null, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
            ResultSet.HOLD_CURSORS_OVER_COMMIT);
}

From source file:edu.yale.cs.hadoopdb.connector.AbstractDBRecordReader.java

/**
 * Method sets up a connection to a database and provides query optimization
 * parameters. Then it executes the query.
 *//*from   w w w . j  a va 2  s  . c  om*/
protected void setupDB(DBInputSplit split, JobConf conf) throws SQLException {

    try {
        startTime = System.currentTimeMillis();
        connection = getConnection(split);
        // Optimization options including specifying forward direction,
        // read-only cursor
        // and a default fetch size to prevent db cache overloading.
        statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        connection.setAutoCommit(false);
        statement.setFetchDirection(ResultSet.FETCH_FORWARD);
        statement.setFetchSize(conf.getInt(DBConst.DB_FETCH_SIZE, DBConst.SQL_DEFAULT_FETCH_SIZE));

        connTime = System.currentTimeMillis();

        String sql = prepareSqlQuery(getSqlQuery(), split, conf);

        LOG.info(sql);
        results = statement.executeQuery(sql);
        queryTime = System.currentTimeMillis();

    } catch (SQLException e) {

        try {
            if (results != null)
                results.close();
            if (statement != null)
                statement.close();
            if (connection != null)
                connection.close();
        } catch (SQLException ex) {
            LOG.info(ex, ex);
        }

        throw e;
    }
}

From source file:com.cloudera.sqoop.mapreduce.db.DBRecordReader.java

protected ResultSet executeQuery(String query) throws SQLException {
    this.statement = connection.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);

    Integer fetchSize = dbConf.getFetchSize();
    if (fetchSize != null) {
        LOG.debug("Using fetchSize for next query: " + fetchSize);
        statement.setFetchSize(fetchSize);
    }/*from   ww w  . j a  v a  2  s.  c o m*/

    LOG.debug("Executing query: " + query);
    return statement.executeQuery();
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraStatement.java

CassandraStatement(CassandraConnection con, String cql) throws SQLException {
    this(con, cql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}