List of usage examples for java.sql ResultSet CONCUR_READ_ONLY
int CONCUR_READ_ONLY
To view the source code for java.sql ResultSet CONCUR_READ_ONLY.
Click Source Link
ResultSet
object that may NOT be updated. From source file:com.norconex.collector.core.data.store.impl.jdbc.JDBCCrawlDataStore.java
@Override public Iterator<ICrawlData> getCacheIterator() { try {//w ww .ja va 2 s .c om final Connection conn = datasource.getConnection(); final Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); final ResultSet rs = stmt.executeQuery(serializer.getSelectCrawlDataSQL(TABLE_CACHE)); if (rs == null || !rs.first()) { return null; } rs.beforeFirst(); return new CrawlDataIterator(TABLE_CACHE, rs, conn, stmt); } catch (SQLException e) { throw new CrawlDataStoreException("Problem getting database cache iterator.", e); } }
From source file:org.apache.jena.jdbc.remote.connections.RemoteEndpointConnection.java
@Override protected JenaStatement createStatementInternal(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 RemoteEndpointStatement(this, this.client, resultSetType, ResultSet.FETCH_FORWARD, 0, resultSetHoldability);//from w ww .java 2s .co m }
From source file:net.sourceforge.msscodefactory.v1_10.MSSBamPg8.MSSBamPg8AnyObjTable.java
public void createAnyObj(MSSBamAuthorization Authorization, MSSBamAnyObjBuff Buff) { final String S_ProcName = "createAnyObj "; if (!schema.isTransactionOpen()) { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Transaction not open"); }/*w w w . j a v a 2s .c o m*/ try { Connection cnx = schema.getCnx(); String ClassCode = Buff.getClassCode(); long Id = schema.nextAnyObjIdGen(); long TenantId = Buff.getRequiredTenantId(); Long ScopeId = Buff.getOptionalScopeId(); String Name = Buff.getRequiredName(); String ShortName = Buff.getOptionalShortName(); String Label = Buff.getOptionalLabel(); String ShortDescription = Buff.getOptionalShortDescription(); String Description = Buff.getOptionalDescription(); Long AuthorId = Buff.getOptionalAuthorId(); int Revision = 1; String sql = "INSERT INTO mssbam110.any_obj( " + "classcode, " + "tenantid, " + "id, " + "scopeid, " + "name, " + "short_name, " + "label, " + "short_descr, " + "descr, " + "authorid" + ", revision )" + "VALUES ( " + MSSBamPg8Schema.getQuotedString(ClassCode) + ", " + TenantId + ", " + Id + ", " + ((ScopeId == null) ? "null" : ScopeId.toString()) + ", " + MSSBamPg8Schema.getQuotedString(Name) + ", " + MSSBamPg8Schema.getQuotedString(ShortName) + ", " + MSSBamPg8Schema.getQuotedString(Label) + ", " + MSSBamPg8Schema.getQuotedString(ShortDescription) + ", " + MSSBamPg8Schema.getQuotedString(Description) + ", " + ((AuthorId == null) ? "null" : AuthorId.toString()) + ", " + Integer.toString(Revision) + " )"; Statement stmt = cnx.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int rowsAffected = stmt.executeUpdate(sql); if (rowsAffected != 1) { throw CFLib.getDefaultExceptionFactory().newRuntimeException(getClass(), S_ProcName, "Expected 1 row to be affected by insert, not " + rowsAffected); } Buff.setRequiredId(Id); Buff.setRequiredRevision(Revision); } catch (SQLException e) { throw CFLib.getDefaultExceptionFactory().newDbException(getClass(), S_ProcName, e); } }
From source file:net.sathis.export.sql.DocBuilder.java
public Map<String, Object> getFields(Map<String, Object> firstRow, ResultSet rs, Entity entity, Map<String, Object> entityMap, Map<String, Object> rootEntityMap) throws SQLException { entityMap = new HashMap<String, Object>(); if (entity.allAttributes.get(MULTI_VALUED) != null && entity.allAttributes.get(MULTI_VALUED).equalsIgnoreCase("true")) { List<Object> fieldArray = new ArrayList<Object>(); rs.beforeFirst();//from w w w .j a v a 2 s .com while (rs.next()) { if (entity.fields.size() > 1) { Map<String, Object> entityFieldsMap = new HashMap<String, Object>(); for (Iterator<Field> iterator = entity.fields.iterator(); iterator.hasNext();) { Field field = (Field) iterator.next(); FieldType fieldType = FieldType.valueOf(field.allAttributes.get("type").toUpperCase()); entityFieldsMap.put(field.name, convertFieldType(fieldType, rs.getObject(field.column)).get(0)); } fieldArray.add(entityFieldsMap); } else if (entity.fields.size() == 1) { fieldArray.add(rs.getObject(entity.fields.get(0).column)); } } rootEntityMap.put(entity.name, fieldArray); } else if (firstRow != null) { for (Iterator<Field> iterator = entity.fields.iterator(); iterator.hasNext();) { Field field = (Field) iterator.next(); FieldType fieldType = FieldType.valueOf(field.allAttributes.get("type").toUpperCase()); if (firstRow.get(field.column) != null) { if (entity.pk != null && entity.pk.equals(field.name)) { if (importer.getDataStoreType().equals(DataStoreType.MONGO)) { entityMap.put("_id", convertFieldType(fieldType, firstRow.get(field.column)).get(0)); } else if (importer.getDataStoreType().equals(DataStoreType.COUCH)) { //couch db says document id must be string entityMap.put("_id", convertFieldType(FieldType.STRING, firstRow.get(field.column)).get(0)); } } else { entityMap.put(field.getName(), convertFieldType(fieldType, firstRow.get(field.column)).get(0)); } params.put(entity.name + "." + field.name, firstRow.get(field.column).toString()); } } } if (entity.entities != null) { Entity subEntity = null; String query = "", aparam = ""; for (Iterator<Entity> iterator = entity.entities.iterator(); iterator.hasNext();) { subEntity = (Entity) iterator.next(); subLevel = subConnection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); query = subEntity.allAttributes.get("query"); m = p.matcher(query); aparam = ""; try { log.info("Parameter Map is: " + params); while (m.find()) { aparam = query.substring(m.start() + 2, m.end() - 1); query = query.replaceAll("(\\$\\{" + aparam + "\\})", Matcher.quoteReplacement(StringEscapeUtils.escapeSql(params.get(aparam)))); m = p.matcher(query); } } catch (Exception e) { e.printStackTrace(); } resultSet = subLevel.executeQuery(query); if (resultSet.next()) { subEntityData = getFields(processor.toMap(resultSet), resultSet, subEntity, null, entityMap); if (subEntityData.size() > 0) entityMap.put(subEntity.name, subEntityData); } resultSet.close(); subLevel.close(); } } return entityMap; }
From source file:com.cloudera.sqoop.manager.TestSqlManager.java
@Test public void getPrimaryKeyFromTable() { // first, create a table with a primary key Connection conn = null;//from w ww.j a va 2 s .c o m try { conn = testServer.getConnection(); PreparedStatement statement = conn.prepareStatement( "CREATE TABLE " + TABLE_WITH_KEY + "(" + KEY_FIELD_NAME + " INT NOT NULL PRIMARY KEY, foo INT)", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.executeUpdate(); statement.close(); } catch (SQLException sqlException) { fail("Could not create table with primary key: " + sqlException.toString()); } finally { if (null != conn) { try { conn.close(); } catch (SQLException sqlE) { LOG.warn("Got SQLException during close: " + sqlE.toString()); } } } String primaryKey = manager.getPrimaryKey(TABLE_WITH_KEY); assertEquals("Expected null pkey for table without key", primaryKey, KEY_FIELD_NAME); }
From source file:jp.mathes.databaseWiki.db.postgres.PostgresBackend.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private PostgresDocument createEmptyDocument(final Connection conn, final String table, final String name, final String db) throws BackendException { Statement st = null;//from w w w. jav a2s . c om Statement st2 = null; ResultSet rs = null; ResultSet rs2 = null; PostgresDocument doc = new PostgresDocument(); doc.setTable(this.getSchemaName(table, db) + "." + this.getPlainTableName(table)); doc.setDatabase(db); doc.setName(name); try { String schema = this.getSchemaName(table, db); String plainTable = this.getPlainTableName(table); st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); StringBuilder sb = new StringBuilder(""); sb.append("select c.column_name, c.column_default, c.data_type, ccu.table_name, ccu.column_name"); sb.append(" from information_schema.columns c"); sb.append(" left join information_schema.key_column_usage kcu"); sb.append(" on kcu.table_schema = c.table_schema and kcu.table_name = c.table_name"); sb.append(" and kcu.column_name = c.column_name"); sb.append(" left join information_schema.table_constraints tc"); sb.append(" on tc.constraint_type='FOREIGN KEY' and tc.table_schema = c.table_schema"); sb.append(" and tc.table_name = c.table_name and tc.constraint_name = kcu.constraint_name"); sb.append(" left join information_schema.constraint_column_usage ccu"); sb.append( " on ccu.constraint_schema = tc.constraint_schema and ccu.constraint_name = tc.constraint_name"); sb.append(" where c.table_schema='%s' and c.table_name='%s'"); sb.append(" order by c.ordinal_position"); String queryString = String.format(sb.toString().replaceAll("[ ]+", " "), schema, plainTable); this.logString(queryString, "?"); rs = st.executeQuery(queryString); if (this.getNumRows(rs) == 0) { throw new BackendException(String.format("Table %s.%s has no columns which is not supported.", this.getSchemaName(table, db), this.getPlainTableName(table))); } String nameField = this.getNameField(conn, table, db); while (rs.next()) { String ctype = rs.getString(3); String cname = rs.getString(1); PostgresField field = null; if ("character varying".equals(ctype)) { field = new PostgresField<String>(); field.setType(FieldType.string); field.setValue(rs.getString(2)); } else if ("text".equals(ctype)) { field = new PostgresField<String>(); field.setType(FieldType.text); field.setValue(rs.getString(2)); } else if ("integer".equals(ctype) || "bigint".equals(ctype) || "smallint".equals(ctype) || "real".equals(ctype)) { field = new PostgresField<Integer>(); field.setType(FieldType.dec); field.setValue(rs.getInt(2)); } else if ("numeric".equals(ctype)) { field = new PostgresField<Double>(); field.setType(FieldType.num); field.setValue(rs.getDouble(2)); } else if ("date".equals(ctype)) { field = new PostgresField<Date>(); field.setType(FieldType.date); field.setValue(rs.getDate(2)); } if (field != null) { field.setName(cname); field.setUsage(FieldUsage.normal); if (nameField.equals(cname)) { field.setValue(name); } else if ("version".equals(cname)) { field.setUsage(FieldUsage.hidden); } String foreignTable = rs.getString(4); String foreignColumn = rs.getString(5); if (!StringUtils.isEmpty(foreignTable) && !StringUtils.isEmpty(foreignColumn)) { st2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); field.setUsage(FieldUsage.fixed); StringBuilder sb2 = new StringBuilder(); sb2.append("select distinct \"%s\" from \"%s\" order by \"%s\""); String queryString2 = String.format(sb2.toString().replaceAll("[ ]+", " "), foreignColumn, foreignTable, foreignColumn); this.logString(queryString2, "?"); rs2 = st2.executeQuery(queryString2); while (rs2.next()) { field.getAllowedValues().add(rs2.getObject(1)); } } doc.addField(cname, field); } } } catch (SQLException e) { throw new BackendException(e); } finally { DbUtils.closeQuietly(rs); DbUtils.closeQuietly(rs2); DbUtils.closeQuietly(st); DbUtils.closeQuietly(st2); } return doc; }
From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java
public void QueryLoad() { final String sql = "SELECT TOP(word,10) AS word, COUNT(*) as count FROM publicdata:samples.shakespeare"; this.logger.info("Test number: 01"); this.logger.info("Running query:" + sql); try {/*from ww w. j a v a 2s.c o m*/ //Statement stmt = BQResultSetFunctionTest.con.createStatement(); Statement stmt = BQForwardOnlyResultSetFunctionTest.con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); stmt.setQueryTimeout(500); BQForwardOnlyResultSetFunctionTest.Result = stmt.executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(BQForwardOnlyResultSetFunctionTest.Result); }
From source file:com.cloudera.sqoop.TestAvroImportExportRoundtrip.java
private void checkFirstColumnSum() throws SQLException { Connection conn = getConnection(); PreparedStatement statement = conn.prepareStatement("SELECT SUM(INTFIELD1) FROM " + getTableName(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); int actualVal = 0; try {/*from www . j a va 2 s. co m*/ ResultSet rs = statement.executeQuery(); try { rs.next(); actualVal = rs.getInt(1); } finally { rs.close(); } } finally { statement.close(); } assertEquals("First column column sum", HsqldbTestServer.getFirstColSum(), actualVal); }
From source file:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurveAnalysis.java
private void initializeGridPoints() throws SQLException { Statement stmt = null;/*from ww w . j a v a 2s. co m*/ ResultSet rs = null; //connect to db try { Table sqlTable = new Table(tableName.getNameForDatabase()); SelectQuery select = new SelectQuery(); select.addColumn(sqlTable, regressorVariable.getName().nameForDatabase()); stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(select.toString()); Min min = new Min(); Max max = new Max(); Mean mean = new Mean(); StandardDeviation sd = new StandardDeviation(); double value = 0.0; while (rs.next()) { value = rs.getDouble(regressorVariable.getName().nameForDatabase()); if (!rs.wasNull()) { min.increment(value); max.increment(value); mean.increment(value); sd.increment(value); } updateProgress(); } rs.close(); stmt.close(); //evaluation points double sdv = sd.getResult(); double mn = mean.getResult(); double lower = mn - 2.5 * sdv; double upper = mn + 2.5 * sdv; bwAdjustment *= sdv; bandwidth = new NonparametricIccBandwidth(sampleSize, bwAdjustment); gridPoints = command.getFreeOption("gridpoints").getInteger(); // uniformDistributionApproximation = new UniformDistributionApproximation( // min.getResult(), max.getResult(), gridPoints); uniformDistributionApproximation = new UniformDistributionApproximation(lower, upper, gridPoints); } catch (SQLException ex) { throw ex; } finally { if (rs != null) rs.close(); if (stmt != null) stmt.close(); } }
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; }