Java Code Examples for java.sql.ResultSet#getStatement()
The following examples show how to use
java.sql.ResultSet#getStatement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RDBMSCollectionQuery.java From ontopia with Apache License 2.0 | 6 votes |
protected Object processResult(TicketIF ticket, ResultSet rs) throws Exception { Collection result; try { // Prepare result collection result = createCollection(); // Zero or more rows expected while (rs.next()) { // Add row object to result collection result.add(stm.readValue(ticket, rs, 0, lookup_identities)); } } finally { Statement _stm = rs.getStatement(); // Close result set rs.close(); rs = null; // Close statement if (_stm != null) _stm.close(); } return result; }
Example 2
Source File: QueryPerfClient.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void queryQueryData(int i, int queryType) throws SQLException { String stmt = this.queryFactory.getQuery(queryType, i); ResultSet rs = null; int rss = 0; long start = this.querystats.startQuery(); switch (this.queryAPI) { case QueryPrms.MYSQL: case QueryPrms.MYSQLC: case QueryPrms.ORACLE: case QueryPrms.GPDB: case QueryPrms.RTE: case QueryPrms.GFXD: rs = ((SQLQueryFactory) this.queryFactory) .execute(stmt, this.connection); rss = ((SQLQueryFactory)this.queryFactory).readResultSet(queryType, rs); break; default: unsupported(); } Statement s = rs.getStatement(); rs.close(); s.close(); this.querystats.endQuery(start, rss, this.histogram); }
Example 3
Source File: RDBMSObjectQuery.java From ontopia with Apache License 2.0 | 6 votes |
protected Object processResult(TicketIF ticket, ResultSet rs) throws Exception { try { // Zero or one row expected if (rs.next()) // Object was found return stm.readValue(ticket, rs, 0, lookup_identities); else // No match return null; // FIXME: Should we complain when more than one object was // found? } finally { Statement _stm = rs.getStatement(); // Close result set rs.close(); rs = null; // Close statement if (_stm != null) _stm.close(); } }
Example 4
Source File: QueryPerfClient.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
private void queryQueryData(int i, int queryType) throws SQLException { String stmt = this.queryFactory.getQuery(queryType, i); ResultSet rs = null; int rss = 0; long start = this.querystats.startQuery(); switch (this.queryAPI) { case QueryPrms.MYSQL: case QueryPrms.MYSQLC: case QueryPrms.ORACLE: case QueryPrms.GPDB: case QueryPrms.RTE: case QueryPrms.GFXD: rs = ((SQLQueryFactory) this.queryFactory) .execute(stmt, this.connection); rss = ((SQLQueryFactory)this.queryFactory).readResultSet(queryType, rs); break; default: unsupported(); } Statement s = rs.getStatement(); rs.close(); s.close(); this.querystats.endQuery(start, rss, this.histogram); }
Example 5
Source File: ResultSetEnumerable.java From Quicksql with MIT License | 6 votes |
public void close() { ResultSet savedResultSet = resultSet; if (savedResultSet != null) { try { resultSet = null; final Statement statement = savedResultSet.getStatement(); savedResultSet.close(); if (statement != null) { final Connection connection = statement.getConnection(); statement.close(); if (connection != null) { connection.close(); } } } catch (SQLException e) { // ignore } } }
Example 6
Source File: RemoteMetaTest.java From calcite-avatica with Apache License 2.0 | 6 votes |
@Test public void testRemoteColumnsMeta() throws Exception { ConnectionSpec.getDatabaseLock().lock(); try { // Verify all columns are retrieved, thus that frame-based fetching works correctly // for columns int rowCount = 0; try (AvaticaConnection conn = (AvaticaConnection) DriverManager.getConnection(url)) { ResultSet rs = conn.getMetaData().getColumns(null, null, null, null); Statement stmt = rs.getStatement(); while (rs.next()) { rowCount++; } rs.close(); // The implicitly created statement should have been closed assertTrue(stmt.isClosed()); } // default fetch size is 100, we are well beyond it assertTrue(rowCount > 900); } finally { ConnectionSpec.getDatabaseLock().unlock(); } }
Example 7
Source File: PostgreSqlUtil.java From aceql-http with GNU Lesser General Public License v2.1 | 6 votes |
/** * Extract the Large Object Input Stream from PostgreSQL * * @param resultSet * the Result Set to extract the blob from * @param columnIndex * the index of column * @return the Large Object Input Stream from PostgreSQL * @throws SQLException */ public static InputStream getPostgreSqlnputStream(ResultSet resultSet, int columnIndex) throws SQLException { InputStream in; Statement statement = resultSet.getStatement(); Connection conn = statement.getConnection(); // Get the Large Object Manager to perform operations with LargeObjectManager lobj = ((org.postgresql.PGConnection) conn) .getLargeObjectAPI(); long oid = resultSet.getLong(columnIndex); if (oid < 1) { return null; } LargeObject obj = lobj.open(oid, LargeObjectManager.READ); in = obj.getInputStream(); return in; }
Example 8
Source File: J2EEDataSourceTest.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
private void assertStatementOK(String dsName, Connection conn, Statement s) throws SQLException { // checks currently only implemented for embedded if (usingEmbedded()) { SecurityCheck.assertSourceSecurity(s, "java.sql.Statement"); } Connection c1 = s.getConnection(); if (c1 != conn) { // with DerbyNetClient and any kind of DataSource, this goes wrong if (!usingDerbyNetClient() && (dsName.indexOf("DataSource") >= 0)) fail ("incorrect connection object returned for Statement.getConnection()"); } s.addBatch("insert into intTable values 1"); s.addBatch("insert into intTable values 2,3"); int[] states = s.executeBatch(); if (states[0] != 1) fail ("invalid update count for first batch statement"); if (states[1] != 2) fail ("invalid update count for second batch statement"); ResultSet rs = s.executeQuery("VALUES 1"); if (rs.getStatement() != s) fail ("incorrect Statement object returned for ResultSet.getStatement for " + dsName); rs.close(); s.close(); }
Example 9
Source File: JdbcMeta.java From calcite-avatica with Apache License 2.0 | 5 votes |
/** * Registers a StatementInfo for the given ResultSet, returning the id under * which it is registered. This should be used for metadata ResultSets, which * have an implicit statement created. */ private int registerMetaStatement(ResultSet rs) throws SQLException { final int id = statementIdGenerator.getAndIncrement(); StatementInfo statementInfo = new StatementInfo(rs.getStatement()); statementInfo.setResultSet(rs); statementCache.put(id, statementInfo); return id; }
Example 10
Source File: ResourceRegistryStandardImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public void register(ResultSet resultSet, Statement statement) { log.tracef( "Registering result set [%s]", resultSet ); if ( statement == null ) { try { statement = resultSet.getStatement(); } catch (SQLException e) { throw convert( e, "unable to access Statement from ResultSet" ); } } if ( statement != null ) { Set<ResultSet> resultSets = xref.get( statement ); // Keep this at DEBUG level, rather than warn. Numerous connection pool implementations can return a // proxy/wrapper around the JDBC Statement, causing excessive logging here. See HHH-8210. if ( log.isDebugEnabled() && resultSets == null ) { log.debug( "ResultSet statement was not registered (on register)" ); } if ( resultSets == null || resultSets == Collections.EMPTY_SET ) { resultSets = new HashSet<ResultSet>(); xref.put( statement, resultSets ); } resultSets.add( resultSet ); } else { unassociatedResultSets.add( resultSet ); } }
Example 11
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void assertStatementOK(String dsName, Connection conn, Statement s) throws SQLException { // checks currently only implemented for embedded if (usingEmbedded()) { SecurityCheck.assertSourceSecurity(s, "java.sql.Statement"); } Connection c1 = s.getConnection(); if (c1 != conn) { // with DerbyNetClient and any kind of DataSource, this goes wrong if (!usingDerbyNetClient() && (dsName.indexOf("DataSource") >= 0)) fail ("incorrect connection object returned for Statement.getConnection()"); } s.addBatch("insert into intTable values 1"); s.addBatch("insert into intTable values 2,3"); int[] states = s.executeBatch(); if (states[0] != 1) fail ("invalid update count for first batch statement"); if (states[1] != 2) fail ("invalid update count for second batch statement"); ResultSet rs = s.executeQuery("VALUES 1"); if (rs.getStatement() != s) fail ("incorrect Statement object returned for ResultSet.getStatement for " + dsName); rs.close(); s.close(); }
Example 12
Source File: DataSourceTest.java From spliceengine with GNU Affero General Public License v3.0 | 5 votes |
private void assertStatementOK(String dsName, Connection conn, Statement s) throws SQLException { // checks currently only implemented for embedded if (usingEmbedded()) { SecurityCheck.assertSourceSecurity(s, "java.sql.Statement"); } Connection c1 = s.getConnection(); if (c1 != conn) { // with DerbyNetClient and any kind of DataSource, this goes wrong if (!usingDerbyNetClient() && (dsName.indexOf("DataSource") >= 0)) fail ("incorrect connection object returned for Statement.getConnection()"); } s.addBatch("insert into intTable values 1"); s.addBatch("insert into intTable values 2,3"); int[] states = s.executeBatch(); if (states[0] != 1) fail ("invalid update count for first batch statement"); if (states[1] != 2) fail ("invalid update count for second batch statement"); ResultSet rs = s.executeQuery("VALUES 1"); if (rs.getStatement() != s) fail ("incorrect Statement object returned for ResultSet.getStatement for " + dsName); rs.close(); s.close(); }
Example 13
Source File: J2EEDataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void assertStatementOK(String dsName, Connection conn, Statement s) throws SQLException { // checks currently only implemented for embedded if (usingEmbedded()) { SecurityCheck.assertSourceSecurity(s, "java.sql.Statement"); } Connection c1 = s.getConnection(); if (c1 != conn) { // with DerbyNetClient and any kind of DataSource, this goes wrong if (!usingDerbyNetClient() && (dsName.indexOf("DataSource") >= 0)) fail ("incorrect connection object returned for Statement.getConnection()"); } s.addBatch("insert into intTable values 1"); s.addBatch("insert into intTable values 2,3"); int[] states = s.executeBatch(); if (states[0] != 1) fail ("invalid update count for first batch statement"); if (states[1] != 2) fail ("invalid update count for second batch statement"); ResultSet rs = s.executeQuery("VALUES 1"); if (rs.getStatement() != s) fail ("incorrect Statement object returned for ResultSet.getStatement for " + dsName); rs.close(); s.close(); }
Example 14
Source File: ResultSetWriter.java From aceql-http with GNU Lesser General Public License v2.1 | 5 votes |
/** * Returns true if engine is terradata * * @param resultSet the result set in use * @returns true if engine is terradata * @throws SQLException */ private String getDatabaseProductName(ResultSet resultSet) throws SQLException { Statement statement = resultSet.getStatement(); // happens on Metadata requests, we don' care about the result: if (statement == null) { return "unknown"; } else { Connection connection = statement.getConnection(); return new SqlUtil(connection).getDatabaseProductName(); } }
Example 15
Source File: ExtDataStoreUtils.java From ade with GNU General Public License v3.0 | 5 votes |
/** * Overload of cleanup( S, R ) when only R is visible to caller. * * @param R - JDBC ResultSet object */ public static synchronized void cleanup(ResultSet R) { Statement S = null; if (R != null) { try { S = R.getStatement(); } catch (Throwable t) { surfaceThrowable("cleanup() called ResultSet.getStatement()", t); } cleanup(S, R); } }
Example 16
Source File: DatabaseProvider.java From sqoop-on-spark with Apache License 2.0 | 5 votes |
/** * Close given result set (if not null) and associated statement. * * @param rs ResultSet to close. */ public void closeResultSetWithStatement(ResultSet rs) { if(rs != null) { try { Statement stmt = rs.getStatement(); rs.close(); stmt.close(); } catch (SQLException e) { LOG.info("Ignoring exception: ", e); } } }
Example 17
Source File: DataSourceTest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private void assertStatementOK(String dsName, Connection conn, Statement s) throws SQLException { // checks currently only implemented for embedded if (usingEmbedded()) { SecurityCheck.assertSourceSecurity(s, "java.sql.Statement"); } Connection c1 = s.getConnection(); if (c1 != conn) { // with DerbyNetClient and any kind of DataSource, this goes wrong if (!usingDerbyNetClient() && (dsName.indexOf("DataSource") >= 0)) fail ("incorrect connection object returned for Statement.getConnection()"); } s.addBatch("insert into intTable values 1"); s.addBatch("insert into intTable values 2,3"); int[] states = s.executeBatch(); if (states[0] != 1) fail ("invalid update count for first batch statement"); if (states[1] != 2) fail ("invalid update count for second batch statement"); ResultSet rs = s.executeQuery("VALUES 1"); if (rs.getStatement() != s) fail ("incorrect Statement object returned for ResultSet.getStatement for " + dsName); rs.close(); s.close(); }
Example 18
Source File: XATest.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Check the held state of a ResultSet by fetching one row, executing a * commit and then fetching the next. Checks the held state matches the * behaviour. */ private static void checkHeldRS(Connection conn, Statement s, ResultSet rs) throws SQLException { // DERBY-1008 - can't run with client if (!usingDerbyNetClient()) { if (s.getConnection() != conn) fail("FAIL - mismatched statement & Connection"); } if (rs.getStatement() != s) { // DERBY-1009 fail("FAIL - mismatched statement & ResultSet " + " Statement class " + s.getClass() + " ResultSet' Statements class " + rs.getStatement().getClass()); } boolean held = (ResultSet.HOLD_CURSORS_OVER_COMMIT == s .getResultSetHoldability()); rs.next(); assertEquals(0, rs.getInt(1)); conn.commit(); try { rs.next(); } catch (SQLException sqle) { boolean ok = !held; if (ok) { assertSQLState("XCL16", sqle); } else { fail("Held cursor closed on commit"); } } rs.close(); conn.commit(); }
Example 19
Source File: DB.java From jactiverecord with MIT License | 5 votes |
void close(ResultSet rs) { if (rs != null) { try { Statement s = rs.getStatement(); rs.close(); close(s); } catch (SQLException e) { throw new RuntimeException("close ResultSet fail", e); } } }
Example 20
Source File: QuicksqlServerMeta.java From Quicksql with MIT License | 5 votes |
/** * Registers a StatementInfo for the given ResultSet, returning the id under which it is registered. This should be * used for metadata ResultSets, which have an implicit statement created. */ private int registerMetaStatement(ResultSet rs) throws SQLException { final int id = statementIdGenerator.getAndIncrement(); StatementInfo statementInfo = new StatementInfo(rs.getStatement()); statementInfo.setResultSet(rs); statementCache.put(id, statementInfo); return id; }