Example usage for java.sql ResultSet CONCUR_UPDATABLE

List of usage examples for java.sql ResultSet CONCUR_UPDATABLE

Introduction

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

Prototype

int CONCUR_UPDATABLE

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

Click Source Link

Document

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

Usage

From source file:com.taobao.datax.plugins.writer.pgsqlwriter.PgsqlWriter.java

@Override
public int startWrite(LineReceiver receiver) {
    com.mysql.jdbc.Statement stmt = null;
    try {/*  w  w w .j  ava 2 s.c  o  m*/

        this.connection = DBSource.getConnection(this.sourceUniqKey);
        stmt = (com.mysql.jdbc.Statement) ((org.apache.commons.dbcp.DelegatingConnection) this.connection)
                .getInnermostDelegate()
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

        /* set max count */
        this.logger.info(String.format("Config max_error_count: set max_error_count=%d", MAX_ERROR_COUNT));
        stmt.executeUpdate(String.format("set max_error_count=%d;", MAX_ERROR_COUNT));

        /* set connect encoding */
        this.logger.info(String.format("Config encoding %s .", this.encoding));
        for (String sql : this.makeLoadEncoding(encoding))
            stmt.execute(sql);

        /* load data begin */
        String loadSql = this.makeLoadSql();
        this.logger.info(String.format("Load sql: %s.", visualSql(loadSql)));

        PgsqlWriterInputStreamAdapter localInputStream = new PgsqlWriterInputStreamAdapter(receiver, this);
        stmt.setLocalInfileInputStream(localInputStream);
        stmt.executeUpdate(visualSql(loadSql));
        this.lineCounter = localInputStream.getLineNumber();

        this.logger.info("DataX write to mysql ends .");

        return PluginStatus.SUCCESS.value();
    } catch (Exception e2) {
        if (null != this.connection) {
            try {
                this.connection.close();
            } catch (SQLException e) {
            }
        }
        throw new DataExchangeException(e2.getCause());
    } finally {
        if (null != stmt)
            try {
                stmt.close();
            } catch (SQLException e3) {
            }
    }
}

From source file:com.taobao.datax.plugins.writer.sqlserverwriter.SqlserverWriter.java

@Override
public int startWrite(LineReceiver receiver) {
    com.mysql.jdbc.Statement stmt = null;
    try {// w w w  .  j a va  2  s. c  o m

        this.connection = DBSource.getConnection(this.sourceUniqKey);
        stmt = (com.mysql.jdbc.Statement) ((org.apache.commons.dbcp.DelegatingConnection) this.connection)
                .getInnermostDelegate()
                .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

        /* set max count */
        this.logger.info(String.format("Config max_error_count: set max_error_count=%d", MAX_ERROR_COUNT));
        stmt.executeUpdate(String.format("set max_error_count=%d;", MAX_ERROR_COUNT));

        /* set connect encoding */
        this.logger.info(String.format("Config encoding %s .", this.encoding));
        for (String sql : this.makeLoadEncoding(encoding))
            stmt.execute(sql);

        /* load data begin */
        String loadSql = this.makeLoadSql();
        this.logger.info(String.format("Load sql: %s.", visualSql(loadSql)));

        SqlserverWriterInputStreamAdapter localInputStream = new SqlserverWriterInputStreamAdapter(receiver,
                this);
        stmt.setLocalInfileInputStream(localInputStream);
        stmt.executeUpdate(visualSql(loadSql));
        this.lineCounter = localInputStream.getLineNumber();

        this.logger.info("DataX write to mysql ends .");

        return PluginStatus.SUCCESS.value();
    } catch (Exception e2) {
        if (null != this.connection) {
            try {
                this.connection.close();
            } catch (SQLException e) {
            }
        }
        throw new DataExchangeException(e2.getCause());
    } finally {
        if (null != stmt)
            try {
                stmt.close();
            } catch (SQLException e3) {
            }
    }
}

From source file:org.apache.ambari.server.checks.CheckDatabaseHelper.java

protected void checkForConfigsSelectedMoreThanOnce() {
    String GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY = "select c.cluster_name, ccm.type_name from clusterconfigmapping ccm "
            + "join clusters c on ccm.cluster_id=c.cluster_id " + "group by c.cluster_name, ccm.type_name "
            + "having sum(selected) > 1";
    Multimap<String, String> clusterConfigTypeMap = HashMultimap.create();
    ResultSet rs = null;//from  ww w.j  a va2 s  .  c  om
    try {
        Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        rs = statement.executeQuery(GET_CONFIGS_SELECTED_MORE_THAN_ONCE_QUERY);
        if (rs != null) {
            while (rs.next()) {
                clusterConfigTypeMap.put(rs.getString("cluster_name"), rs.getString("type_name"));
            }

            for (String clusterName : clusterConfigTypeMap.keySet()) {
                LOG.error(
                        "You have config(s), in cluster {}, that is(are) selected more than once in clusterconfigmapping table: {}",
                        clusterName, StringUtils.join(clusterConfigTypeMap.get(clusterName), ","));
                errorAvailable = true;
            }
        }

    } catch (SQLException e) {
        LOG.error("Exception occurred during check for config selected more than ones procedure: ", e);
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.error("Exception occurred during result set closing procedure: ", e);
            }
        }
    }
}

From source file:org.globus.workspace.scheduler.defaults.DefaultSchedulerAdapterDB.java

/**
 * Database agnostic way to manage indexes
 *
 * What is stored in the row is the last ID that was USED already.
 *
 * This is O(1) now, not O(numNodes)/*from  w  ww .j  av  a 2s  .co m*/
 *
 * @param numNodes number of IDs needed
 * @return next request IDs
 * @throws WorkspaceDatabaseException exc
 */
synchronized int[] getNextTasktIds(int numNodes) throws WorkspaceDatabaseException {

    PreparedStatement pstmt = null;
    PreparedStatement pstmt2 = null;
    ResultSet rs = null;
    Connection c = null;
    int lastTaskId = -1;
    int newLastTaskId = -1;
    try {
        c = getConnection();

        pstmt = c.prepareStatement(DefaultSchedulerConstants.SQL_SELECT_DEFAULT_SCHED_REQ_ID,
                ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs = pstmt.executeQuery();

        if (!rs.next()) {
            // if there is no row in database, this is first time an ID
            // is needed, insert the value do not update it
            lastTaskId = 0;
            newLastTaskId = numNodes;
            pstmt2 = c.prepareStatement(DefaultSchedulerConstants.SQL_INSERT_DEFAULT_SCHED_REQ_ID);
            pstmt2.setInt(1, newLastTaskId);
            pstmt2.executeUpdate();
        } else {
            lastTaskId = rs.getInt(1);

            // Get the req Id and increment it
            newLastTaskId = lastTaskId + numNodes;

            pstmt2 = c.prepareStatement(DefaultSchedulerConstants.SQL_UPDATE_DEFAULT_SCHED_REQ_ID);
            pstmt2.setInt(1, newLastTaskId);
            pstmt2.executeUpdate();
        }
    } catch (SQLException e) {
        throw new WorkspaceDatabaseException(e);
    } finally {
        try {
            if (pstmt != null) {
                pstmt.close();
            }
            if (pstmt2 != null) {
                pstmt2.close();
            }
            if (rs != null) {
                rs.close();
            }
            if (c != null) {
                returnConnection(c);
            }
        } catch (SQLException e) {
            logger.error("SQLException in finally cleanup", e);
        }
    }

    if (lastTaskId < 0) {
        throw new WorkspaceDatabaseException("lastTaskId not expected " + "to be negative here");
    }
    if (newLastTaskId < 0) {
        throw new WorkspaceDatabaseException("newLastTaskId not expected" + " to be negative here");
    }

    if (newLastTaskId - lastTaskId != numNodes) {
        throw new WorkspaceDatabaseException("difference expected to be " + "equal to numNodes here");
    }

    final int[] ret = new int[numNodes];
    for (int i = 0; i < numNodes; i++) {
        lastTaskId += 1;
        ret[i] = lastTaskId;
    }
    return ret;
}

From source file:IDlook.java

public void connectToDB() {
    try {/*w  w  w .j  a  v a  2  s . c om*/
        connection = DriverManager
                .getConnection("jdbc:mysql://192.168.1.25/identification?user=spider&password=spider");
        statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

    } catch (SQLException connectException) {
        System.out.println(connectException.getMessage());
        System.out.println(connectException.getSQLState());
        System.out.println(connectException.getErrorCode());
        System.exit(1);
    }
}

From source file:gov.nih.nci.migration.MigrationDriver.java

private void setAESEncryption() throws EncryptionException, SQLException {
    Connection connection = getConnection();
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

    ResultSet resultSet = stmt.executeQuery("SELECT * FROM CSM_CONFIGURATION_PROPS");
    String aesEncryptionKey = null;
    String md5HashKey = null;//w  w w. ja v a  2s .  com
    while (resultSet.next()) {
        String propertyKey = resultSet.getString("PROPERTY_KEY");
        if ("AES_ENCRYPTION_KEY".equals(propertyKey))
            aesEncryptionKey = resultSet.getString("PROPERTY_VALUE");
        if ("MD5_HASH_KEY".equals(propertyKey))
            md5HashKey = resultSet.getString("PROPERTY_VALUE");
        if ("PASSWORD_EXPIRY_DAYS".equals(propertyKey))
            expiryDays = resultSet.getString("PROPERTY_VALUE");
    }
    setExpiryDays(expiryDays);
    aesEncryption = new AESEncryption(aesEncryptionKey, Boolean.parseBoolean(md5HashKey));
}

From source file:com.itemanalysis.jmetrik.stats.ranking.RankingAnalysis.java

public String compute() throws SQLException {
    Statement stmt = null;//from  w  w w  . j a  v a  2s  .c o m
    ResultSet rs = null;

    try {
        //get data
        ResizableDoubleArray data = getData();

        //create columns - dao uses its own transaction
        int numberOfColumns = dao.getColumnCount(conn, tableName);
        int columnNumber = numberOfColumns + 1;
        String newVariableLabel = "Rank";
        if (blom)
            newVariableLabel = "Blom Normal Score";
        if (tukey)
            newVariableLabel = "Tukey Normal Score";
        if (vdw)
            newVariableLabel = "van der Waerden Normal Score";
        if (ntiles)
            newVariableLabel = "Quantiles: " + numGroups + " groups";
        newVariable = new VariableAttributes(newVariableName, newVariableLabel, ItemType.NOT_ITEM,
                DataType.DOUBLE, columnNumber++, "");

        dao.addColumnToDb(conn, tableName, newVariable);

        //compute ranks
        NaturalRanking ranking = new NaturalRanking(NaNStrategy.REMOVED, tiesStrategy);
        double[] ranks = ranking.rank(data.getElements());

        //begin transaction
        conn.setAutoCommit(false);

        //connect to table and update values
        SelectQuery select = new SelectQuery();
        Table sqlTable = new Table(tableName.getNameForDatabase());
        select.addColumn(sqlTable, newVariable.getName().nameForDatabase());
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        rs = stmt.executeQuery(select.toString());

        int nRanks = ranks.length;
        int rankIndex = 0;//array index for ranks (missing values not included)
        int dbIndex = 0;//db row position for case (missing values included)
        double r = Double.NaN;
        boolean missing = false;
        String tempName = "";
        while (rs.next()) {
            missing = missingIndex.contains(dbIndex);
            if (missing) {
                rs.updateNull(newVariable.getName().nameForDatabase());
            } else {
                r = ranks[rankIndex];
                if (blom) {
                    rs.updateDouble(newVariable.getName().nameForDatabase(),
                            normScore.blom(r, (double) nRanks));
                } else if (tukey) {
                    rs.updateDouble(newVariable.getName().nameForDatabase(),
                            normScore.tukey(r, (double) nRanks));
                } else if (vdw) {
                    rs.updateDouble(newVariable.getName().nameForDatabase(),
                            normScore.vanderWaerden(r, (double) nRanks));
                } else if (ntiles) {
                    rs.updateDouble(newVariable.getName().nameForDatabase(),
                            getGroup(r, (double) nRanks, (double) numGroups));
                } else {
                    rs.updateDouble(newVariable.getName().nameForDatabase(), r);
                }
                rankIndex++;
            }
            rs.updateRow();
            updateProgress();
            dbIndex++;
        }
        conn.commit();
        return "Ranks computed";
    } catch (SQLException ex) {
        conn.rollback();
        throw ex;
    } finally {
        if (rs != null)
            rs.close();
        if (stmt != null)
            stmt.close();
        conn.setAutoCommit(true);
    }

}

From source file:nl.strohalm.cyclos.utils.JDBCWrapper.java

/**
 * Execute a sql query, returning an updatable, open result set
 *///from   www  .  ja va2 s  .  c om
public ResultSet updatableQuery(final String sql, final Object... parameters) throws SQLException {
    return doQuery(sql, ResultSet.CONCUR_UPDATABLE, parameters);
}

From source file:net.solarnetwork.node.dao.jdbc.JdbcSettingDao.java

private void storeSettingInternal(final String key, final String ttype, final String value, final int flags) {
    final String type = (ttype == null ? "" : ttype);
    final Timestamp now = new Timestamp(System.currentTimeMillis());
    // to avoid bumping modified date column when values haven't changed, we are careful here
    // to compare before actually updating
    getJdbcTemplate().query(new PreparedStatementCreator() {

        @Override//from   w ww .ja v  a2  s. co m
        public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
            PreparedStatement queryStmt = con.prepareStatement(sqlGet, ResultSet.TYPE_SCROLL_SENSITIVE,
                    ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT);
            queryStmt.setString(1, key);
            queryStmt.setString(2, type);
            return queryStmt;
        }
    }, new ResultSetExtractor<Object>() {

        @Override
        public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
            if (rs.next()) {
                String oldValue = rs.getString(1);
                if (!value.equals(oldValue)) {
                    rs.updateString(1, value);
                    rs.updateTimestamp(2, now);
                    rs.updateRow();
                }
            } else {
                rs.moveToInsertRow();
                rs.updateString(1, value);
                rs.updateTimestamp(2, now);
                rs.updateString(3, key);
                rs.updateString(4, type);
                rs.updateInt(5, flags);
                rs.insertRow();
            }
            return null;
        }
    });
}

From source file:com.sun.faces.mock.MockResultSet.java

public int getConcurrency() throws SQLException {

    return (ResultSet.CONCUR_UPDATABLE);

}