List of usage examples for java.sql ResultSet CONCUR_UPDATABLE
int CONCUR_UPDATABLE
To view the source code for java.sql ResultSet CONCUR_UPDATABLE.
Click Source Link
ResultSet
object that may be updated. From source file:net.firejack.platform.core.config.upgrader.SchemaUpgrader.java
/** * This method update database package version and increase version number * * @param packageLookup - Openflame Package lookup * @param version - database version * @return version/*w w w . j a va 2s.com*/ */ private Version updateDatabaseVersion(String packageLookup, Version version) { try { Connection connection = dataSource.getConnection(); try { connection.setAutoCommit(true); Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); statement.addBatch("UPDATE opf_registry_node SET database_version = " + version.getToVersion() + " " + "WHERE lookup = '" + packageLookup + "';"); try { statement.executeBatch(); return new Version(version.getToVersion()); } finally { JdbcUtils.closeStatement(statement); } } finally { connection.setAutoCommit(false); JdbcUtils.closeConnection(connection); } } catch (SQLException e) { throw new RuntimeException(e); } }
From source file:com.strider.datadefender.DatabaseAnonymizer.java
/** * Creates the SELECT query for key and update columns. * // w w w . j a v a 2 s. c o m * @param tableName * @param keys * @param columns * @return */ private PreparedStatement getSelectQueryStatement(final IDBFactory dbFactory, final Table table, final Collection<String> keys, final Collection<String> columns) throws SQLException { final List<String> params = new LinkedList<>(); final StringBuilder query = new StringBuilder("SELECT DISTINCT "); query.append(StringUtils.join(keys, ", ")).append(", ").append(StringUtils.join(columns, ", ")) .append(" FROM ").append(table.getName()); final List<Exclude> exclusions = table.getExclusions(); if (exclusions != null) { String separator = " WHERE ("; for (final Exclude exc : exclusions) { final String eq = exc.getEqualsValue(); final String lk = exc.getLikeValue(); final boolean nl = exc.isExcludeNulls(); final String col = exc.getName(); if (col != null && col.length() != 0) { if (eq != null) { query.append(separator).append('(').append(col).append(" != ? OR ").append(col) .append(" IS NULL)"); params.add(eq); separator = AND; } if (lk != null && lk.length() != 0) { query.append(separator).append('(').append(col).append(" NOT LIKE ? OR ").append(col) .append(" IS NULL)"); params.add(lk); separator = AND; } if (nl) { query.append(separator).append(col).append(" IS NOT NULL"); separator = AND; } } } if (query.indexOf(" WHERE (") != -1) { separator = ") AND ("; } for (final Exclude exc : exclusions) { final String neq = exc.getNotEqualsValue(); final String nlk = exc.getNotLikeValue(); final String col = exc.getName(); if (neq != null) { query.append(separator).append(col).append(" = ?"); separator = " OR "; } if (nlk != null && nlk.length() != 0) { query.append(separator).append(col).append(" LIKE ?"); separator = " OR "; } } if (query.indexOf(" WHERE (") != -1) { query.append(')'); } } final PreparedStatement stmt = dbFactory.getConnection().prepareStatement(query.toString(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); if (dbFactory.getVendorName().equalsIgnoreCase("mysql")) { stmt.setFetchSize(Integer.MIN_VALUE); } int paramIndex = 1; for (final String param : params) { stmt.setString(paramIndex, param); ++paramIndex; } log.debug("Querying for: " + query.toString()); if (params.size() > 0) { log.debug("\t - with parameters: " + StringUtils.join(params, ',')); } return stmt; }
From source file:io.cloudslang.content.database.utils.SQLInputsUtils.java
@NotNull private static Map<String, Integer> createConcurValues() { final Map<String, Integer> concurValues = new HashMap<>(); concurValues.put(CONCUR_READ_ONLY, ResultSet.CONCUR_READ_ONLY); concurValues.put(CONCUR_UPDATABLE, ResultSet.CONCUR_UPDATABLE); return concurValues; }
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 w w. j a va2 s . co m*/ 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:com.oracle.tutorial.jdbc.CoffeesTable.java
public void insertRow(String coffeeName, int supplierID, float price, int sales, int total) throws SQLException { Statement stmt = null;/* w w w .ja v a 2 s.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.SQLInputsUtilsTest.java
@Test public void getResultSetConcurrencySimple() throws Exception { assertEquals(ResultSet.CONCUR_READ_ONLY, getResultSetConcurrency(CONCUR_READ_ONLY)); assertEquals(ResultSet.CONCUR_UPDATABLE, getResultSetConcurrency(CONCUR_UPDATABLE)); }
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 {// w ww .j av a 2s. 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:com.tascape.qa.th.db.H2Handler.java
@Override public void updateSuiteExecutionResult(String execId) throws SQLException { LOG.info("Update test suite execution result with execution id {}", execId); int total = 0, fail = 0; try (Connection conn = this.getConnection();) { final String sql1 = "SELECT " + Test_Result.EXECUTION_RESULT.name() + " FROM " + TestResult.TABLE_NAME + " WHERE " + Test_Result.SUITE_RESULT.name() + " = ?;"; try (PreparedStatement stmt = conn.prepareStatement(sql1)) { stmt.setString(1, execId);//from w ww . j a va 2 s .co m ResultSet rs = stmt.executeQuery(); while (rs.next()) { total++; String result = rs.getString(Test_Result.EXECUTION_RESULT.name()); if (!result.equals(ExecutionResult.PASS.name()) && !result.endsWith("/0")) { fail++; } } } } try (Connection conn = this.getConnection();) { final String sql = "SELECT * FROM " + SuiteResult.TABLE_NAME + " WHERE " + SuiteResult.SUITE_RESULT_ID + " = ?;"; try (PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE)) { stmt.setString(1, execId); ResultSet rs = stmt.executeQuery(); if (rs.first()) { rs.updateInt(SuiteResult.NUMBER_OF_TESTS, total); rs.updateInt(SuiteResult.NUMBER_OF_FAILURE, fail); rs.updateString(SuiteResult.EXECUTION_RESULT, fail == 0 ? "PASS" : "FAIL"); rs.updateLong(SuiteResult.STOP_TIME, System.currentTimeMillis()); rs.updateRow(); } } } }
From source file:de.xwic.sandbox.server.installer.impl.SQLServerDatabaseHandler.java
public boolean renameScope(String oldScope, String newScope) { boolean exist = false; try {//from w w w . j av a 2 s.co m String sql = "SELECT NAME FROM CRM_SEC_SCOPE WHERE NAME = '" + newScope + "'"; Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); try { if (stmt.execute(sql)) { ResultSet rs = stmt.getResultSet(); if (rs.next()) { exist = true; } } } finally { stmt.close(); } // determine if the newScope does not exist? if (exist) { return false; } stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); sql = "UPDATE CRM_SEC_SCOPE SET NAME = '" + newScope + "' WHERE NAME = '" + oldScope + "'"; try { if (stmt.executeUpdate(sql) != 1) { log.warn("More than one entry with the name " + oldScope + " have been found."); } } finally { stmt.close(); } // now update the SCOPE.propNAME scope types stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); sql = "SELECT NAME FROM CRM_SEC_SCOPE WHERE NAME LIKE '" + oldScope + ".%'"; try { if (stmt.execute(sql)) { ResultSet rs = stmt.getResultSet(); while (rs.next()) { String oldName = rs.getString("NAME"); String propertyName = oldName.substring(oldScope.length() + 1); String newName = newScope + "." + propertyName; //rs.updateString("NAME", newName); //rs.updateRow(); Statement stmtUpdate = connection.createStatement(); try { String sqlUpdate = "UPDATE CRM_SEC_SCOPE SET NAME = '" + newName + "' WHERE NAME='" + oldName + "'"; int num = stmtUpdate.executeUpdate(sqlUpdate); if (num == 0) { log.warn("Warning: RENAME FAILED FROM " + oldName + " TO " + newName); } } finally { stmtUpdate.close(); } } } } finally { stmt.close(); } // else, rename the scope + all dependent scopes // that include the property names // oldScopeName + ".%" return true; } catch (Exception e) { // the update process should not be aborted when this happens, so // its just a warning log.warn("Error renaming '" + oldScope + "', into '" + newScope + "'", e); return false; } }
From source file:org.apache.ambari.server.checks.CheckDatabaseHelper.java
protected void checkHostComponentStatesCountEqualsHostComponentsDesiredStates() { String GET_HOST_COMPONENT_STATE_COUNT_QUERY = "select count(*) from hostcomponentstate"; String GET_HOST_COMPONENT_DESIRED_STATE_COUNT_QUERY = "select count(*) from hostcomponentdesiredstate"; String GET_MERGED_TABLE_ROW_COUNT_QUERY = "select count(*) FROM hostcomponentstate hcs " + "JOIN hostcomponentdesiredstate hcds ON hcs.service_name=hcds.service_name AND hcs.component_name=hcds.component_name AND hcs.host_id=hcds.host_id"; int hostComponentStateCount = 0; int hostComponentDesiredStateCount = 0; int mergedCount = 0; ResultSet rs = null;//w w w . java2 s. co m try { Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); rs = statement.executeQuery(GET_HOST_COMPONENT_STATE_COUNT_QUERY); if (rs != null) { while (rs.next()) { hostComponentStateCount = rs.getInt(1); } } rs = statement.executeQuery(GET_HOST_COMPONENT_DESIRED_STATE_COUNT_QUERY); if (rs != null) { while (rs.next()) { hostComponentDesiredStateCount = rs.getInt(1); } } rs = statement.executeQuery(GET_MERGED_TABLE_ROW_COUNT_QUERY); if (rs != null) { while (rs.next()) { mergedCount = rs.getInt(1); } } if (hostComponentStateCount != hostComponentDesiredStateCount || hostComponentStateCount != mergedCount) { LOG.error( "Your host component states (hostcomponentstate table) count not equals host component desired states (hostcomponentdesiredstate table) count!"); errorAvailable = true; } } catch (SQLException e) { LOG.error( "Exception occurred during check for same count of host component states and host component desired states: ", e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { LOG.error("Exception occurred during result set closing procedure: ", e); } } } }