Example usage for java.sql ResultSet TYPE_SCROLL_SENSITIVE

List of usage examples for java.sql ResultSet TYPE_SCROLL_SENSITIVE

Introduction

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

Prototype

int TYPE_SCROLL_SENSITIVE

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

Click Source Link

Document

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

Usage

From source file:org.apache.openjpa.jdbc.kernel.JDBCFetchConfigurationImpl.java

public JDBCFetchConfiguration setResultSetType(int type) {
    if (type != DEFAULT && type != ResultSet.TYPE_FORWARD_ONLY && type != ResultSet.TYPE_SCROLL_INSENSITIVE
            && type != ResultSet.TYPE_SCROLL_SENSITIVE)
        throw new IllegalArgumentException(_loc.get("bad-resultset-type", Integer.valueOf(type)).getMessage());

    if (type == DEFAULT) {
        JDBCConfiguration conf = getJDBCConfiguration();
        if (conf != null)
            _state.type = conf.getResultSetTypeConstant();
    } else/*from   w  w  w  .java  2s .co  m*/
        _state.type = type;
    return this;
}

From source file:recite18th.library.Db.java

public static List get(String sqlSelect, String fqnModel) {
    List list = new ArrayList();
    try {/*from w w w  .  j  av a2 s. c o  m*/
        Logger.getLogger(Db.class.getName()).log(Level.INFO, "get : {0}", sqlSelect);
        PreparedStatement pstmt = getCon().prepareStatement(sqlSelect, ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        list = getDataSetAsArrayList(pstmt, fqnModel);
    } catch (SQLException ex) {
        Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
    }
    return list;
}

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

protected void checkForHostsWithoutState() {
    String GET_HOSTS_WITHOUT_STATUS_QUERY = "select host_name from hosts where host_id not in (select host_id from hoststate)";
    Set<String> hostsWithoutStatus = new HashSet<>();
    ResultSet rs = null;/*from w  ww.j  av  a 2 s .  c om*/
    try {
        Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        rs = statement.executeQuery(GET_HOSTS_WITHOUT_STATUS_QUERY);
        if (rs != null) {
            while (rs.next()) {
                hostsWithoutStatus.add(rs.getString("host_name"));
            }

            if (!hostsWithoutStatus.isEmpty()) {
                LOG.error("You have host(s) without state (in hoststate table): "
                        + StringUtils.join(hostsWithoutStatus, ","));
                errorAvailable = true;
            }
        }

    } catch (SQLException e) {
        LOG.error("Exception occurred during check for host without state 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.apache.jena.jdbc.remote.connections.RemoteEndpointConnection.java

@Override
protected JenaPreparedStatement createPreparedStatementInternal(String sparql, int resultSetType,
        int resultSetConcurrency, int resultSetHoldability) throws SQLException {
    if (this.isClosed())
        throw new SQLException("Cannot create a statement after the connection was closed");
    if (resultSetType == ResultSet.TYPE_SCROLL_SENSITIVE)
        throw new SQLFeatureNotSupportedException(
                "Remote endpoint backed connection do not support scroll sensitive result sets");
    if (resultSetConcurrency != ResultSet.CONCUR_READ_ONLY)
        throw new SQLFeatureNotSupportedException(
                "Remote endpoint backed connections only support read-only result sets");
    return new RemoteEndpointPreparedStatement(sparql, this, this.client, resultSetType,
            ResultSet.FETCH_FORWARD, 0, resultSetHoldability);
}

From source file:us.mn.state.health.lims.reports.action.implementation.reportBeans.CSVColumnBuilder.java

protected void buildResultSet() throws SQLException {
    makeSQL();/*w  ww . j a va 2s  .co  m*/
    String sql = query.toString();
    //System.out.println("===1===\n" + sql.substring(0, 7000)); // the SQL is chunked out only because Eclipse thinks printing really big strings to the console must be wrong, so it truncates them
    //System.out.println("===2===\n" + sql.substring(7000));
    Session session = HibernateUtil.getSession().getSessionFactory().openSession();
    PreparedStatement stmt = session.connection().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,
            ResultSet.CONCUR_READ_ONLY);
    resultSet = stmt.executeQuery();
}

From source file:com.oracle.tutorial.jdbc.CoffeesTable.java

public void insertRow(String coffeeName, int supplierID, float price, int sales, int total)
        throws SQLException {
    Statement stmt = null;//from  w  ww  .  j  a va 2s  .  c  o m
    try {
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet uprs = stmt.executeQuery("SELECT * FROM COFFEES");

        uprs.moveToInsertRow();

        uprs.updateString("COF_NAME", coffeeName);
        uprs.updateInt("SUP_ID", supplierID);
        uprs.updateFloat("PRICE", price);
        uprs.updateInt("SALES", sales);
        uprs.updateInt("TOTAL", total);

        uprs.insertRow();
        uprs.beforeFirst();

    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}

From source file:io.cloudslang.content.database.utils.SQLInputsUtils.java

@NotNull
private static Map<String, Integer> createTypeValues() {
    final Map<String, Integer> typeValues = new HashMap<>();
    typeValues.put(TYPE_FORWARD_ONLY, ResultSet.TYPE_FORWARD_ONLY);
    typeValues.put(TYPE_SCROLL_INSENSITIVE, ResultSet.TYPE_SCROLL_INSENSITIVE);
    typeValues.put(TYPE_SCROLL_SENSITIVE, ResultSet.TYPE_SCROLL_SENSITIVE);
    return typeValues;
}

From source file:orca.registry.DatabaseOperations.java

License:asdf

public void testQuery(String query) {

    Connection conn = null;//from  www  . j  a  v  a2s.com

    try {

        log.debug("Inside DatabaseOperations: testQuery()");
        //System.out.println("Trying to get a new instance");
        log.debug("Inside DatabaseOperations: testQuery() - Trying to get a new instance");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        //System.out.println("Trying to get a database connection");
        log.debug("Inside DatabaseOperations: testQuery() - Trying to get a database connection");
        conn = DriverManager.getConnection(url, userName, password);
        //System.out.println ("Database connection established");
        log.debug("Inside DatabaseOperations: testQuery() - Database connection established");

        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet srs = stmt.executeQuery("SELECT * FROM Actors");

        while (srs.next()) {
            String act_name = srs.getString("act_name");
            String act_guid = srs.getString("act_guid");
            //System.out.println("Actor Name: " + act_name + " | Actor GUID: " + act_guid );
            log.debug("Actor Name: " + act_name + " | Actor GUID: " + act_guid);
        }
        srs.close();

    } catch (Exception e) {
        //System.err.println ("Cannot query the database server: " + e);
        log.error("Cannot query the database server: " + e.toString());
    } finally {
        if (conn != null) {
            try {
                conn.close();
                //System.out.println ("Database connection terminated");
                log.error("Database connection terminated");
            } catch (Exception e) { /* ignore close errors */
            }
        }
    }
}

From source file:com.chiorichan.database.DatabaseEngine.java

public int queryUpdate(String query, Object... args) throws SQLException {
    PreparedStatement stmt = null;

    if (con == null)
        throw new SQLException("The SQL connection is closed or was never opened.");

    try {/*from  w  w w. j a  v a2s .c  o m*/
        stmt = con.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

        int x = 0;

        for (Object s : args)
            try {
                x++;
                stmt.setString(x, ObjectUtil.castToString(s));
            } catch (SQLException e) {
                if (!e.getMessage().startsWith("Parameter index out of range"))
                    throw e;
            }

        stmt.execute();

        Loader.getLogger().fine("Update Query: \"" + stmt.toString() + "\" which affected "
                + stmt.getUpdateCount() + " row(s).");
    } catch (MySQLNonTransientConnectionException e) {
        if (reconnect())
            return queryUpdate(query);
    } catch (CommunicationsException e) {
        if (reconnect())
            return queryUpdate(query);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return stmt.getUpdateCount();
}

From source file:org.dbinterrogator.mssql.MSSQLInstance.java

/**
 * List Databases//from w  w  w. jav a2s  .c  om
 *
 * @return List of databases
 */
public ArrayList<String> listDatabases() {
    ArrayList<String> databases = new ArrayList();
    try {
        Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        s.executeQuery("SELECT name FROM sys.databases");
        ResultSet rs = s.getResultSet();
        while (rs.next()) {
            databases.add(rs.getString(1));
        }
    } catch (SQLException e) {
        System.err.println(e.getMessage());
    }
    if (verbose) {
        System.out.println(databases);
    }
    return databases;
}