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.netspective.axiom.sql.Query.java

protected PreparedStatement createStatement(ConnectionContext cc, Object[] overrideParams, boolean scrollable,
        QueryExecutionLogEntry logEntry) throws NamingException, SQLException {
    logEntry.registerGetConnectionBegin();
    Connection conn = cc.getConnection();
    logEntry.registerGetConnectionEnd(conn);
    PreparedStatement stmt = null;
    DbmsSqlText sqlText = getSqlText(cc);
    String sql = sqlText.getSql(cc);
    if (scrollable)
        stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    else// w  w w.java2s. c om
        stmt = conn.prepareStatement(sql);

    logEntry.registerBindParamsBegin();
    if (overrideParams != null) {
        for (int i = 0; i < overrideParams.length; i++)
            stmt.setObject(i + 1, overrideParams[i]);
    } else {
        final QueryParameters parameters = sqlText.getParams();
        if (parameters != null)
            parameters.apply(cc, stmt);
    }
    logEntry.registerBindParamsEnd();
    return stmt;
}

From source file:edu.ku.brc.specify.toycode.mexconabio.CopyFromGBIF.java

/**
 * //from  w  ww  .jav  a  2  s .c o  m
 */
public void processMissingGenusSpecies() {
    String pSQL = "UPDATE raw SET genus=?, species=?, subspecies=? WHERE id = ?";

    String where = " WHERE genus IS NULL AND species IS NULL AND scientific_name IS NOT NULL";
    String gbifSQLBase = "SELECT id, scientific_name FROM raw" + where;

    long totalRecs = BasicSQLUtils.getCount(srcDBConn, "SELECT COUNT(*) FROM raw " + where);
    long procRecs = 0;
    long startTime = System.currentTimeMillis();
    int secsThreshold = 0;

    PrintWriter pw = null;

    final double HRS = 1000.0 * 60.0 * 60.0;

    Statement gStmt = null;
    PreparedStatement pStmt = null;

    try {
        pw = new PrintWriter("gbif.log");

        pStmt = dbConn.prepareStatement(pSQL);

        System.out.println("Total Records: " + totalRecs);
        pw.println("Total Records: " + totalRecs);

        gStmt = srcDBConn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        gStmt.setFetchSize(Integer.MIN_VALUE);

        System.out.println(gbifSQLBase);

        ResultSet gRS = gStmt.executeQuery(gbifSQLBase);
        while (gRS.next()) {
            int id = gRS.getInt(1);
            pStmt.setObject(4, id);

            String[] gs = StringUtils.split(gRS.getString(2), ' ');
            switch (gs.length) {
            case 1:
                pStmt.setString(1, gs[0]);
                pStmt.setString(2, null);
                pStmt.setString(3, null);
                break;

            case 2:
                pStmt.setString(1, gs[0]);
                pStmt.setString(2, gs[1]);
                pStmt.setString(3, null);
                break;

            case 3:
                pStmt.setString(1, gs[0]);
                pStmt.setString(2, gs[1]);
                pStmt.setString(3, gs[2]);
                break;

            default:
                continue;
            }
            try {
                pStmt.executeUpdate();

            } catch (Exception ex) {
                System.err.println("For ID[" + gRS.getObject(1) + "][" + gRS.getObject(2) + "]");
                ex.printStackTrace();
                pw.print("For ID[" + gRS.getObject(1) + "] " + ex.getMessage());
                pw.flush();
            }

            procRecs++;
            if (procRecs % 10000 == 0) {
                long endTime = System.currentTimeMillis();
                long elapsedTime = endTime - startTime;

                double avergeTime = (double) elapsedTime / (double) procRecs;

                double hrsLeft = (((double) elapsedTime / (double) procRecs) * (double) totalRecs - procRecs)
                        / HRS;

                int seconds = (int) (elapsedTime / 60000.0);
                if (secsThreshold != seconds) {
                    secsThreshold = seconds;

                    String msg = String.format(
                            "Elapsed %8.2f hr.mn   Ave Time: %5.2f    Percent: %6.3f  Hours Left: %8.2f ",
                            ((double) (elapsedTime)) / HRS, avergeTime,
                            100.0 * ((double) procRecs / (double) totalRecs), hrsLeft);
                    System.out.println(msg);
                    pw.println(msg);
                    pw.flush();
                }
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();

    } finally {
        try {
            if (gStmt != null) {
                gStmt.close();
            }
            if (pStmt != null) {
                pStmt.close();
            }
            pw.close();

        } catch (Exception ex) {

        }
    }
    System.out.println("Done transferring.");
    pw.println("Done transferring.");
}

From source file:com.nridge.core.ds.rdbms.hsqldb.HDBSQLTable.java

private void queryFunction(String aSQLStatement, DataTable aTable, int aLimit) throws NSException {
    Logger appLogger = mAppMgr.getLogger(this, "queryFunction");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    Statement stmtQuery = null;//from w w w  .  j  a va 2  s  .  c  o m
    appLogger.debug(aSQLStatement);
    Connection jdbcConnection = mSQLConnection.getJDBCConnection();
    try {
        stmtQuery = jdbcConnection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        if (aLimit > 0)
            stmtQuery.setFetchSize(aLimit);
        stmtQuery.setEscapeProcessing(mSQLConnection.isStatementEscapingEnabled());
        mSQLConnection.setLastStatement(aSQLStatement);
        ResultSet resultSet = stmtQuery.executeQuery(aSQLStatement);
        while (resultSet.next())
            addTableRowFromFunctionResultSet(aTable, resultSet);
    } catch (SQLException e) {
        throw new NSException("RDBMS Query Error: " + aSQLStatement + " : " + e.getMessage(), e);
    } finally {
        if (stmtQuery != null) {
            try {
                stmtQuery.close();
            } catch (SQLException ignored) {
            }
        }
    }

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8ChainTable.java

public MSSBamChainBuff readBuffByIdIdx(MSSBamAuthorization Authorization, long Id) {
    final String S_ProcName = "readBuffByIdIdx";
    try {//  www. ja  v a 2s. co m
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectChainBuff + "WHERE " + "anyo.Id = " + Long.toString(Id) + " ";
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        if (resultSet.next()) {
            MSSBamChainBuff buff = unpackChainResultSetToBuff(resultSet);
            if (resultSet.next()) {
                resultSet.last();
                throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                        "Did not expect multi-buff response, " + resultSet.getRow() + " rows selected");
            }
            return (buff);
        } else {
            return (null);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}

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

/**
 * Executes an arbitrary SQL statement.//from  ww  w.  j a v a 2 s. co m
 * @param stmt The SQL statement to execute
 * @param fetchSize Overrides default or parameterized fetch size
 * @return A ResultSet encapsulating the results or null on error
 */
protected ResultSet execute(String stmt, Integer fetchSize, Object... args) throws SQLException {
    // Release any previously-open statement.
    release();

    PreparedStatement statement = null;
    statement = this.getConnection().prepareStatement(stmt, ResultSet.TYPE_FORWARD_ONLY,
            ResultSet.CONCUR_READ_ONLY);
    if (fetchSize != null) {
        LOG.debug("Using fetchSize for next query: " + fetchSize);
        statement.setFetchSize(fetchSize);
    }
    this.lastStatement = statement;
    if (null != args) {
        for (int i = 0; i < args.length; i++) {
            statement.setObject(i + 1, args[i]);
        }
    }

    LOG.info("Executing SQL statement: " + stmt);
    return statement.executeQuery();
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8BoolDefTable.java

public MSSBamBoolDefBuff[] readAllDerived(MSSBamAuthorization Authorization) {
    final String S_ProcName = "readAllDerived";
    MSSBamBoolDefBuff[] buffArray;//from w w  w. j ava2  s  . c o m
    if (!schema.isTransactionOpen()) {
        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                "Transaction not open");
    }
    String classCode;
    ArrayList<String> classCodeList = new ArrayList<String>();
    try {
        Connection cnx = schema.getCnx();
        String sql = S_sqlSelectBoolDefDistinctClassCode;
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        ResultSet resultSet = stmt.executeQuery(sql);
        while (resultSet.next()) {
            classCode = resultSet.getString(1);
            classCodeList.add(classCode);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
    ArrayList<MSSBamBoolDefBuff> resultList = new ArrayList<MSSBamBoolDefBuff>();
    for (int classCodeIdx = 0; classCodeIdx < classCodeList.size(); classCodeIdx++) {
        MSSBamBoolDefBuff[] subList;
        classCode = classCodeList.get(classCodeIdx);
        if (classCode.equals("BLN")) {
            subList = readAllBuff(Authorization);
        } else if (classCode.equals("TBLN")) {
            subList = schema.getTableTableBool().readAllBuff(Authorization);
        } else if (classCode.equals("SBLN")) {
            subList = schema.getTableSchemaBool().readAllBuff(Authorization);
        } else {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Did not expect ClassCode \"" + classCode + "\"");
        }
        for (int idxSubList = 0; idxSubList < subList.length; idxSubList++) {
            resultList.add(subList[idxSubList]);
        }
    }
    buffArray = resultList.toArray(new MSSBamBoolDefBuff[0]);
    return (buffArray);
}

From source file:fr.bird.bloom.model.GeographicTreatment.java

/**
 * Convert the iso2 code (2 letters) to iso3 code (3 letters)
 * /*from  www  .  j  a v a 2 s .com*/
 * @param String iso2
 * @return String iso3
 */
public String convertIso2ToIso3(String iso2) {
    String iso3 = "";

    Statement statement = null;
    try {
        statement = ConnectionDatabase.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    DatabaseTreatment newConnection = new DatabaseTreatment(statement);

    List<String> messages = new ArrayList<>();
    messages.add("\n--- Convert iso2 code to iso3 code ---");
    String sqlConvertIso2Iso3 = "SELECT iso3_ FROM Workflow.IsoCode WHERE iso2_ = \""
            + iso2.replaceAll("\"", "") + "\";";
    messages.addAll(newConnection.executeSQLcommand("executeQuery", sqlConvertIso2Iso3));

    List<String> resultatConvert = newConnection.getResultatSelect();

    if (resultatConvert.size() != 2) {
        //System.err.println(iso2 + "\t" + resultatConvert + "\t" + listInfos);
        System.err.println("error to convert iso2 to iso3.\n Iso2 : " + iso2);
        iso3 = "error";
    } else {
        iso3 = resultatConvert.get(1).replaceAll("\"", "");
    }
    return iso3;
}

From source file:com.netspective.axiom.sql.Query.java

protected PreparedStatement createStatement(ConnectionContext cc, Object[] overrideParams, boolean scrollable)
        throws NamingException, SQLException {
    Connection conn = cc.getConnection();
    PreparedStatement stmt = null;
    DbmsSqlText sqlText = getSqlText(cc);
    String sql = sqlText.getSql(cc);
    if (scrollable)
        stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    else//from ww  w. j  a  va 2 s  . co m
        stmt = conn.prepareStatement(sql);

    if (overrideParams != null) {
        for (int i = 0; i < overrideParams.length; i++)
            stmt.setObject(i + 1, overrideParams[i]);
    } else {
        final QueryParameters parameters = sqlText.getParams();
        if (parameters != null)
            parameters.apply(cc, stmt);
    }
    return stmt;
}

From source file:edu.ku.brc.specify.conversion.IdHashMapper.java

/**
 * Looks the NewID and returns the OldID
 * @param newId//  ww  w  .j a  va 2 s.c  o  m
 * @return the OldID
 */
@Override
public Integer reverseGet(final Integer newId) {
    if (newId == null) {
        return null;
    }

    try {
        if (stmtNew == null) {
            stmtNew = oldConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        }

        Integer oldId = null;

        ResultSet rs = stmtNew.executeQuery("SELECT OldID FROM " + mapTableName + " WHERE NewID = " + newId);
        if (rs.next()) {
            oldId = rs.getInt(1);

        } else {
            rs.close();
            return null;
        }
        rs.close();

        return oldId;

    } catch (SQLException ex) {
        ex.printStackTrace();
        log.error(ex);
    }
    return null;
}

From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AddressTagTable.java

public void deleteAddressTag(MSSBamAuthorization Authorization, MSSBamAddressTagBuff Buff) {
    final String S_ProcName = "deleteAddressTag";
    try {//  w ww .j a va 2 s  . c om
        Connection cnx = schema.getCnx();
        long AddressId = Buff.getRequiredAddressId();
        long TagId = Buff.getRequiredTagId();
        String TagValue = Buff.getRequiredTagValue();

        int Revision = Buff.getRequiredRevision();
        MSSBamAddressTagBuff readBuff = readBuffByIdIdx(Authorization, AddressId, TagId);
        int oldRevision = readBuff.getRequiredRevision();
        if (oldRevision != Revision) {
            throw CFLib.getDefaultExceptionFactory().newCollisionDetectedException(getClass(), S_ProcName,
                    Buff);
        }
        String sql = "DELETE FROM mssbam110.ctcaddr_tag " + "WHERE " + "AddressId = " + Long.toString(AddressId)
                + " " + "AND " + "TagId = " + Long.toString(TagId) + " " + "AND " + "Revision = "
                + Integer.toString(Revision);
        ;
        Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        int rowsAffected = stmt.executeUpdate(sql);
        if (rowsAffected != 1) {
            throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName,
                    "Expected 1 row to be affected by delete, not " + rowsAffected);
        }
    } catch (SQLException e) {
        throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e);
    }
}