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:com.chiorichan.database.DatabaseEngine.java
public ResultSet query(String query, boolean retried) throws SQLException { Statement stmt = null;//from w ww.j a v a 2 s . c om ResultSet result = null; if (con == null) throw new SQLException("The SQL connection is closed or was never opened."); try { try { stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } catch (CommunicationsException e) { if (reconnect()) stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); } finally { if (stmt == null) stmt = con.createStatement(); } result = stmt.executeQuery(query); Loader.getLogger().fine("SQL Query `" + query + "` returned " + getRowCount(result) + " rows!"); } catch (CommunicationsException | MySQLNonTransientConnectionException e) { if (!retried && reconnect()) return query(query, true); else { throw e; } } catch (Throwable t) { t.printStackTrace(); throw t; } return result; }
From source file:gr.seab.r2rml.test.ComplianceTests.java
private ResultSet query(String query) { ResultSet result = null;/*from w ww .j a va 2s . co m*/ try { if (connection == null) openConnection(); java.sql.Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); log.info("sql query: " + query); result = statement.executeQuery(query); } catch (Exception e) { e.printStackTrace(); } return result; }
From source file:com.taobao.datax.plugins.writer.oraclejdbcwriter.OracleJdbcWriter.java
@Override public int post(PluginParam param) { if (StringUtils.isBlank(this.post)) return PluginStatus.SUCCESS.value(); Statement stmt = null;//from w ww . jav a2s . c om 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) { e.printStackTrace(); 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:com.oracle.tutorial.jdbc.CoffeesFrame.java
public CachedRowSet getContentsOfCoffeesTable() throws SQLException { CachedRowSet crs = null;/*from w w w .jav a2s . c o m*/ try { connection = settings.getConnection(); crs = new CachedRowSetImpl(); crs.setType(ResultSet.TYPE_SCROLL_INSENSITIVE); crs.setConcurrency(ResultSet.CONCUR_UPDATABLE); crs.setUsername(settings.userName); crs.setPassword(settings.password); // In MySQL, to disable auto-commit, set the property relaxAutoCommit to // true in the connection URL. if (this.settings.dbms.equals("mysql")) { crs.setUrl(settings.urlString + "?relaxAutoCommit=true"); } else { crs.setUrl(settings.urlString); } // Regardless of the query, fetch the contents of COFFEES crs.setCommand("select COF_NAME, SUP_ID, PRICE, SALES, TOTAL from COFFEES"); crs.execute(); } catch (SQLException e) { JDBCTutorialUtilities.printSQLException(e); } return crs; }
From source file:com.chiorichan.database.DatabaseEngine.java
public ResultSet query(String query, boolean retried, Object... args) throws SQLException { PreparedStatement stmt = null; ResultSet result = null;//w ww . j a v a 2 s. c o m if (con == null) throw new SQLException("The SQL connection is closed or was never opened."); try { stmt = con.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); int x = 0; for (Object s : args) try { x++; Loader.getLogger().debug(x + " -> " + ObjectUtil.castToString(s)); stmt.setString(x, ObjectUtil.castToString(s)); } catch (SQLException e) { if (!e.getMessage().startsWith("Parameter index out of range")) throw e; } result = stmt.executeQuery(); Loader.getLogger() .fine("SQL Query `" + stmt.toString() + "` returned " + getRowCount(result) + " rows!"); } catch (CommunicationsException | MySQLNonTransientConnectionException e) { if (!retried && reconnect()) return query(query, true, args); else { throw e; } } catch (Throwable t) { t.printStackTrace(); throw t; } return result; }
From source file:gr.seab.r2rml.test.ComplianceTests.java
@Test public void loadPersons() { if (connection == null) openConnection();//w w w. j ava 2 s .c o m for (int i = 94300; i < 500000; i++) { String q1 = "INSERT INTO eperson (eperson_id, email, password, salt, digest_algorithm, firstname, lastname, can_log_in, require_certificate, self_registered, last_active, sub_frequency, phone, netid, language) " + "VALUES (" + i + ", 'nkons" + i + "@live.com', 'aa07c370f18e6306d481e29d04d28ea322f3ac5d746bd1122b4907518b37875b59283054d9e91fd049f39df2223ba3feb62f9cc2923e5614503d0b9b191d6606', '2d0155aa63818899d177ff988ddde7c5', 'SHA-512', '" + randomString() + "', '" + randomString() + "', 'true', 'false', 'false', NULL, NULL, NULL, NULL, 'en');"; String q2 = "INSERT INTO epersongroup2eperson (id, eperson_group_id, eperson_id) VALUES (" + i + ", 1, " + i + ");"; try { java.sql.Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); int a = statement.executeUpdate(q1); int b = statement.executeUpdate(q2); } catch (Exception e) { e.printStackTrace(); } if (i % 1000 == 0) log.info("At " + i); } }
From source file:eu.optimis_project.monitoring.storage.MySQLStorageManager.java
public void dropTable() throws SQLException { final String createTable = "DROP TABLE IF EXISTS " + tableName + ";"; Statement statement = null;/*from w w w. j a v a2 s. co m*/ 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.tascape.reactor.report.MySqlBaseBean.java
public void setSuiteResultInvisible(String srid, boolean invisible) throws NamingException, SQLException { String sql = "UPDATE " + SuiteResult.TABLE_NAME + " SET " + SuiteResult.INVISIBLE_ENTRY + " = ?" + " WHERE " + SuiteResult.SUITE_RESULT_ID + " = ?;"; try (Connection conn = this.getConnection()) { PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); stmt.setBoolean(1, invisible);// w w w . j av a 2 s . co m stmt.setString(2, srid); LOG.trace("{}", stmt); stmt.executeUpdate(); } }
From source file:org.wso2.carbon.registry.core.jdbc.dao.JDBCCommentsVersionDAO.java
/** * Method to get comments added to a given resource. * * @param resource the resource.//w w w . ja va 2 s .com * * @return an array of comments. * @throws RegistryException if an error occurs while getting comments. */ public Comment[] getComments(ResourceImpl resource) throws RegistryException { JDBCDatabaseTransaction.ManagedRegistryConnection conn = JDBCDatabaseTransaction.getConnection(); try { String dbName = conn.getMetaData().getDatabaseProductName(); if (dbName.contains("Microsoft") || dbName.equals("Oracle")) { enableApiPagination = "false"; } } catch (SQLException e) { throw new RegistryException("Failed to get Database product name ", e); } List<Comment> commentList = new ArrayList<Comment>(); PreparedStatement s = null; ResultSet results = null; String path = resource.getPath(); boolean paginated = false; int start = 0; int count = 0; String sortOrder = ""; String sortBy = ""; MessageContext messageContext = null; // enableApiPagination is the value of system property - enable.registry.api.paginating if (enableApiPagination == null || enableApiPagination.equals("true")) { messageContext = MessageContext.getCurrentMessageContext(); if (messageContext != null && PaginationUtils.isPaginationHeadersExist(messageContext)) { PaginationContext paginationContext = PaginationUtils.initPaginationContext(messageContext); start = paginationContext.getStart(); if (start == 0) { start = 1; } count = paginationContext.getCount(); sortBy = paginationContext.getSortBy(); sortOrder = paginationContext.getSortOrder(); paginated = true; } } try { String sql = "SELECT C.REG_ID, C.REG_COMMENT_TEXT, C.REG_USER_ID, C.REG_COMMENTED_TIME " + "FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC " + "WHERE C.REG_ID=RC.REG_COMMENT_ID AND RC.REG_VERSION = ? " + "AND C.REG_TENANT_ID=? AND RC.REG_TENANT_ID=?"; if (paginated) { if (!"".equals(sortBy) && !"".equals(sortOrder)) { sql = sql + " ORDER BY " + sortBy + " " + sortOrder; } } if (enableApiPagination == null || enableApiPagination.equals("true")) { // TYPE_SCROLL_INSENSITIVE and CONCUR_UPDATABLE should be set to move the cursor through the resultSet s = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); } else { s = conn.prepareStatement(sql); } s.setLong(1, resource.getVersionNumber()); s.setInt(2, CurrentSession.getTenantId()); s.setInt(3, CurrentSession.getTenantId()); results = s.executeQuery(); if (paginated) { //Check start index is a valid one if (results.relative(start)) { //This is to get cursor to correct position to execute results.next(). results.previous(); int i = 0; while (results.next() && i < count) { i++; commentList.add(getComment(results, path)); } } else { log.debug("start index doesn't exist in the result set"); } //move the cursor to the last index if (results.last()) { log.debug("cursor move to the last index of result set"); } else { log.debug("cursor doesn't move to the last index of result set"); } //set row count to the message context. PaginationUtils.setRowCount(messageContext, Integer.toString(results.getRow())); } else { while (results.next()) { commentList.add(getComment(results, path)); } } } catch (SQLException e) { String msg = "Failed to get comments on resource " + path + ". " + e.getMessage(); log.error(msg, e); throw new RegistryException(msg, e); } finally { try { try { if (results != null) { results.close(); } } finally { if (s != null) { s.close(); } } } catch (SQLException ex) { String msg = RegistryConstants.RESULT_SET_PREPARED_STATEMENT_CLOSE_ERROR; log.error(msg, ex); } } return commentList.toArray(new Comment[commentList.size()]); }
From source file:nl.nn.adapterframework.jdbc.JdbcQuerySenderBase.java
protected PreparedStatement prepareQuery(Connection con, String query, boolean updateable) throws SQLException { if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "preparing statement for query [" + query + "]"); }//from w w w . j av a 2 s. co m String[] columnsReturned = getColumnsReturnedList(); if (columnsReturned != null) { return prepareQueryWithColunmsReturned(con, query, columnsReturned); } return con.prepareStatement(query, ResultSet.TYPE_FORWARD_ONLY, updateable ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY); }