Example usage for java.sql ResultSet TYPE_SCROLL_INSENSITIVE

List of usage examples for java.sql ResultSet TYPE_SCROLL_INSENSITIVE

Introduction

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

Prototype

int TYPE_SCROLL_INSENSITIVE

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

Click Source Link

Document

The constant indicating the type for a ResultSet object that is scrollable but generally not sensitive to changes to the data that underlies the ResultSet.

Usage

From source file:com.netspective.axiom.connection.BasicConnectionProviderEntry.java

public void init(String dataSourceId, Connection conn) {
    this.dataSourceId = dataSourceId;

    try {/*from   ww  w  . j  a  va2s .c  o  m*/
        try {
            DatabasePolicy policy = DatabasePolicies.getInstance().getDatabasePolicy(conn);
            put(KEYNAME_DATABASE_POLICY_CLASSNAME, policy.getClass().getName());
            put(KEYNAME_DATABASE_POLICY_DBMSID, policy.getDbmsIdentifier());
        } catch (Exception dpe) {
            put(KEYNAME_DATABASE_POLICY_CLASSNAME, dpe.toString());
        }

        DatabaseMetaData dbmd = conn.getMetaData();

        put(KEYNAME_DRIVER_NAME, dbmd.getDriverName());
        put(KEYNAME_DATABASE_PRODUCT_NAME, dbmd.getDatabaseProductName());
        put(KEYNAME_DATABASE_PRODUCT_VERSION, dbmd.getDatabaseProductVersion());
        put(KEYNAME_DRIVER_VERSION, dbmd.getDriverVersion());
        put(KEYNAME_URL, dbmd.getURL());
        put(KEYNAME_USER_NAME, dbmd.getUserName());

        String resultSetType = "unknown";
        if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE))
            resultSetType = "scrollable (insensitive)";
        else if (dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE))
            resultSetType = "scrollable (sensitive)";
        else if (dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY))
            resultSetType = "non-scrollabe (forward only)";
        put(KEYNAME_RESULTSET_TYPE, resultSetType);

        valid = true;
    } catch (Exception e) {
        exception = e;
    } finally {
        try {
            conn.close();
        } catch (SQLException e) {
            log.error("SQL Exception while closing connection", e);
        }
    }
}

From source file:fr.gael.dhus.server.http.webapp.symmetricDS.SymmetricDSWebapp.java

@Override
public void afterPropertiesSet() throws Exception {
    if (!scalabilityManager.getClearDB()) {
        return;//  www  .  jav  a2 s. com
    }
    PreparedStatement ps = datasource.getConnection().prepareStatement(
            "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    ResultSet rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection()
                .prepareStatement("DROP TRIGGER " + rs.getString("TRIGGER_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();

    ps = datasource.getConnection().prepareStatement(
            "SELECT CONSTRAINT_NAME, TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection().prepareStatement("ALTER TABLE "
                + rs.getString("TABLE_NAME") + " DROP CONSTRAINT " + rs.getString("CONSTRAINT_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();

    ps = datasource.getConnection().prepareStatement(
            "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'SYM_%';",
            ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

    rs = ps.executeQuery();
    while (rs.next()) {
        PreparedStatement ps2 = datasource.getConnection()
                .prepareStatement("DROP TABLE " + rs.getString("TABLE_NAME"));
        ps2.execute();
        ps2.close();
    }
    ps.close();
}

From source file:eu.optimis_project.monitoring.storage.MySQLStorageManager.java

private void createTable() throws SQLException {
    final String createTable = "CREATE TABLE IF NOT EXISTS " + tableName + "(" + ENTRIES_COLUMNNAME_SERVICEID
            + " VARCHAR(256) NOT NULL, " + ENTRIES_COLUMNNAME_INSTANCEID + " VARCHAR(256) NOT NULL, "
            + ENTRIES_COLUMNNAME_NAME + " VARCHAR(256) NOT NULL, " + ENTRIES_COLUMNNAME_DATA
            + " VARCHAR(256) NOT NULL, " + ENTRIES_COLUMNNAME_TIMESTAMP + " BIGINT NOT NULL, " + "PRIMARY KEY ("
            + ENTRIES_COLUMNNAME_SERVICEID + ", " + ENTRIES_COLUMNNAME_TIMESTAMP + ", "
            + ENTRIES_COLUMNNAME_NAME + ")" + ");";

    Statement statement = null;/*from ww w  .j  a  v  a  2s .  c  om*/
    try {
        log.debug("Executing query: " + createTable);
        statement = getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        statement.execute(createTable);
    } catch (SQLException e) {
        throw e;
    } finally {
        try {
            if (statement != null) {
                statement.close();
            }
        } catch (SQLException e) {
            log.debug("Failed to close statement.", e);
        }
    }
}

From source file:com.handu.open.dubbo.monitor.dao.base.DubboInvokeBaseDAO.java

/**
 * SQL?/* w ww. j  a  v a2 s  .c o m*/
 *
 * @param sql SQL?
 * @return List<Map>
 */
public List<Map> querySql(String sql) {
    List<Map> list = Lists.newArrayList();
    try {
        ResultSet rs = getSqlSession().getConnection()
                .prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE)
                .executeQuery();
        try {
            ResultSetMetaData rsm = rs.getMetaData(); //
            int col = rsm.getColumnCount(); //
            String[] colName = new String[col];
            //???, colName
            for (int i = 0; i < col; i++) {
                colName[i] = rsm.getColumnName(i + 1);
            }
            rs.beforeFirst();
            while (rs.next()) {
                Map<String, String> map = Maps.newHashMap();
                for (String aColName : colName) {
                    map.put(aColName, rs.getString(aColName));
                }
                list.add(map);
            }
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return list;
}

From source file:org.kawanfw.sql.api.util.PreparedStatementRunner.java

/**
 * Executes a SQL prepared statement for a query.
 * /*from www  .java2s.c  o m*/
 * @return the result set of the prepared statement
 * 
 * @throws SQLException
 *             if a SQL Exception is raised
 */
public ResultSet executeQuery() throws SQLException {
    prepStatement = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,
            ResultSet.CONCUR_READ_ONLY);

    int numberOfIntMarks = StringUtils.countMatches(sql, "?");
    int numberOfParams = params.size();

    if (numberOfIntMarks != numberOfParams) {
        throw new SQLException("sql statement numbers of \"?\" do no match number of parameters: "
                + numberOfIntMarks + " and " + numberOfParams);
    }

    for (int i = 0; i < params.size(); i++) {
        int j = i + 1;
        prepStatement.setObject(j, params.get(i));
    }

    rs = null;

    if (sql.toLowerCase().startsWith(SELECT)) {
        debug("sql query for prepStatement.executeQuery(): " + CR_LF + sql);
        rs = prepStatement.executeQuery();
    } else {
        throw new SQLException("sql string is not a query: " + sql);
    }

    return rs;
}

From source file:org.eks.utils.AggregateValues.java

protected String doTheSQLQuery(String inQueryStr) throws SQLException {
    String jsonResult = "[";

    Connection co = ConnectionHelper.getConnection(null);
    if (co != null) {
        try {//from  w  ww  .  jav  a  2 s  . com
            Statement st = co.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

            ResultSet rs = st.executeQuery(inQueryStr);
            while (rs.next()) {
                jsonResult += "{\"label\":\"" + rs.getString("label") + "\", \"count\":" + rs.getInt("count")
                        + "},";
            }
            rs.close();
            // Remove last comma.
            // If there was nothing, then reduce to empty
            if (jsonResult.equals("[")) {
                jsonResult = "[]";
            } else {
                jsonResult = jsonResult.substring(0, jsonResult.length() - 1) + "]";
            }

        } catch (SQLException e) {
            // . . .
            throw e;
        } finally {
            co.close();
        }
    }

    return jsonResult;
}

From source file:com.taobao.datax.plugins.writer.mysqlwriter.MysqlWriter.java

@Override
public int post(PluginParam param) {
    if (StringUtils.isBlank(this.post))
        return PluginStatus.SUCCESS.value();

    /*/*  w w w. ja  v  a  2 s  . c om*/
     * add by bazhen.csy if (null == this.connection) { throw new
     * DataExchangeException(String.format(
     * "MysqlWriter connect %s failed in post work .", this.host)); }
     */

    Statement stmt = null;
    try {
        this.connection = DBSource.getConnection(this.sourceUniqKey);

        stmt = this.connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

        for (String subSql : this.post.split(";")) {
            this.logger.info(String.format("Excute prepare sql %s .", subSql));
            stmt.execute(subSql);
        }

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

    }
}

From source file:net.mlw.vlh.adapter.jdbc.util.ConfigurableStatementBuilder.java

/**
 * @see net.mlw.vlh.adapter.jdbc.util.StatementBuilder#generate(java.sql.Connection, java.lang.StringBuffer, java.util.Map, boolean)
 */// w  w  w  .j  av a 2  s . co m
public PreparedStatement generate(Connection conn, StringBuffer query, Map whereClause, boolean scrollable)
        throws SQLException, ParseException {
    if (!init) {
        init();
    }

    if (whereClause == null) {
        whereClause = Collections.EMPTY_MAP;
    }

    for (Iterator iter = textManipulators.iterator(); iter.hasNext();) {
        TextManipulator manipulator = (TextManipulator) iter.next();
        manipulator.manipulate(query, whereClause);
    }

    LinkedList arguments = new LinkedList();

    // Replace any "{key}" with the value in the whereClause Map,
    // then placing the value in the partameters list.
    for (int i = 0, end = 0, start; ((start = query.toString().indexOf('{', end)) >= 0); i++) {
        end = query.toString().indexOf('}', start);

        String key = query.substring(start + 1, end);

        Object value = whereClause.get(key);
        if (value == null) {
            throw new NullPointerException("Property '" + key + "' was not provided.");
        }
        arguments.add(new NamedPair(key, value));
        Setter setter = getSetter(key);
        query.replace(start, end + 1, setter.getReplacementString(value));
        end -= (key.length() + 2);
    }

    PreparedStatement statement = null;
    if (scrollable) {
        statement = conn.prepareStatement(query.toString(), ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
    } else {
        statement = conn.prepareStatement(query.toString());
    }

    int index = 1;
    // Now set all the patameters on the statement.
    for (Iterator iter = arguments.iterator(); iter.hasNext();) {
        NamedPair namedPair = (NamedPair) iter.next();
        Setter setter = getSetter(namedPair.getName());
        try {
            index = setter.set(statement, index, namedPair.getValue());
        } catch (RuntimeException e) {
            String message = "Cannot set value of " + namedPair.getName() + " (setter = " + setter + ")";
            LOGGER.error(message, e);
            throw new RuntimeException(message, e);
        }
    }

    return statement;
}

From source file:DbManager.java

/**
 * Provide the PreparedStatement, given a query.
 * //from  w w  w. j  ava  2  s  .  c  o  m
 * @param query
 *            the query.
 * @return the PreparedStatement based on the query.
 */
public PreparedStatement prepareStatement(String query) {
    try {
        pstmt = con.prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        return pstmt;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.misc.datafactory.sql.SimpleSQLReportDataFactory.java

private int getBestResultSetType(final DataRow dataRow) throws SQLException {
    if ("simple".equalsIgnoreCase(getConfiguration().getConfigProperty( //$NON-NLS-1$
            ResultSetTableModelFactory.RESULTSET_FACTORY_MODE))) { //$NON-NLS-1$
        return ResultSet.TYPE_FORWARD_ONLY;
    }/*from w w  w  . j  a v a 2  s  . co m*/

    final Connection connection = getConnection(dataRow);
    final boolean supportsScrollInsensitive = connection.getMetaData()
            .supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
    final boolean supportsScrollSensitive = connection.getMetaData()
            .supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);

    if (supportsScrollInsensitive) {
        return ResultSet.TYPE_SCROLL_INSENSITIVE;
    }
    if (supportsScrollSensitive) {
        return ResultSet.TYPE_SCROLL_SENSITIVE;
    }
    return ResultSet.TYPE_FORWARD_ONLY;
}