@Override public ResultSet getResultSet() throws SQLException { return rawStatement.getResultSet(); }
@Override public ResultSet getResultSet() throws SQLException { return rawStatement.getResultSet(); }
/** {@inheritDoc} */ @Override public ResultSet getResultSet() throws SQLException { return delegate.getResultSet(); }
@Override public ResultSet getResultSet() throws SQLException { Preconditions.checkArgument(1 == routedStatements.size(), "Cannot support getResultSet for DDL"); return routedStatements.iterator().next().getResultSet(); }
private List extractCurrentResults() { try { return extractResults( jdbcStatement.getResultSet() ); } catch (SQLException e) { throw convert( e, "Error calling CallableStatement.getResultSet" ); } }
@Override public synchronized long getRowCount(Session session) { //The foo alias is used to support the PostgreSQL syntax String sql = "SELECT COUNT(*) FROM " + qualifiedTableName + " as foo"; try { PreparedStatement prep = execute(sql, null, false); ResultSet rs = prep.getResultSet(); rs.next(); long count = rs.getLong(1); rs.close(); reusePreparedStatement(prep, sql); return count; } catch (Exception e) { throw wrapException(sql, e); } }
Iterator<String> iter = strs.iterator(); do { rs = stmt.getResultSet(); String ph = iter.next();
private void executePreparedStatement() throws SQLException { try (final Connection connection = dataSource.getConnection()) { final PreparedStatement preparedStatement = connection.prepareStatement("SELECT * from STAGEMONITOR"); preparedStatement.execute(); final ResultSet resultSet = preparedStatement.getResultSet(); resultSet.next(); } }
@Test public void testExecuteQuery() throws Exception { try (Connection connection = createConnection(); PreparedStatement statement = connection.prepareStatement("SELECT ?, ?")) { statement.setInt(1, 123); statement.setString(2, "hello"); try (ResultSet rs = statement.executeQuery()) { assertTrue(rs.next()); assertEquals(rs.getInt(1), 123); assertEquals(rs.getString(2), "hello"); assertFalse(rs.next()); } assertTrue(statement.execute()); try (ResultSet rs = statement.getResultSet()) { assertTrue(rs.next()); assertEquals(rs.getInt(1), 123); assertEquals(rs.getString(2), "hello"); assertFalse(rs.next()); } } }
@Override public ResultSet execute(PreparedStatement statement) { // sql logged by StatementPreparerImpl try { final ResultSet rs; try { jdbcExecuteStatementStart(); if ( !statement.execute() ) { while ( !statement.getMoreResults() && statement.getUpdateCount() != -1 ) { // do nothing until we hit the resultset } } rs = statement.getResultSet(); } finally { jdbcExecuteStatementEnd(); } postExtract( rs, statement ); return rs; } catch (SQLException e) { throw sqlExceptionHelper.convert( e, "could not execute statement" ); } }
/** * @throws Exception If failed. */ @Test public void testTime() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where timeVal is not distinct from ?"); stmt.setTime(1, new Time(1)); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, TIME); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
/** * @throws Exception If failed. */ @Test public void testDouble() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where doubleVal is not distinct from ?"); stmt.setDouble(1, 1.0d); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, DOUBLE); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
/** * @throws Exception If failed. */ @Test public void testString() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where strVal is not distinct from ?"); stmt.setString(1, "str"); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, VARCHAR); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
/** * @throws Exception If failed. */ @Test public void testByte() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where byteVal is not distinct from ?"); stmt.setByte(1, (byte)1); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, TINYINT); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
/** * @throws Exception If failed. */ @Test public void testLong() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where longVal is not distinct from ?"); stmt.setLong(1, 1L); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, BIGINT); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
/** * @throws Exception If failed. */ @Test public void testDate() throws Exception { stmt = conn.prepareStatement(SQL_PART + " where dateVal is not distinct from ?"); stmt.setObject(1, new Date(1)); ResultSet rs = stmt.executeQuery(); int cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 1; cnt++; } assert cnt == 1; stmt.setNull(1, DATE); stmt.execute(); rs = stmt.getResultSet(); cnt = 0; while (rs.next()) { if (cnt == 0) assert rs.getInt("id") == 2; cnt++; } assert cnt == 1; }
private static Supplier<ResultSet> getResultSet(Supplier<PreparedStatement> supplier, StatementContext ctx) { return () -> { try { ResultSet rs = supplier.get().getResultSet(); if (rs == null) { if (ctx.getConfig(ResultProducers.class).allowNoResults) { return new EmptyResultSet(); } throw new NoResultsException("Statement returned no results", ctx); } ctx.addCleanable(rs::close); return rs; } catch (SQLException e) { throw new ResultSetException("Could not get result set", e, ctx); } }; }
@Test @TestForIssue(jiraKey = "HHH-12138") public void testNamedNativeQueryStoredProcedureRefCursorWithJDBC() { EntityManager entityManager = createEntityManager(); entityManager.getTransaction().begin(); try { Session session = entityManager.unwrap( Session.class ); session.doWork( connection -> { try ( PreparedStatement function = connection.prepareStatement( "select * from fn_person_and_phones( ? )" ) ) { function.setInt( 1, 1 ); function.execute(); try ( ResultSet resultSet = function.getResultSet() ) { while ( resultSet.next() ) { Long postCommentId = resultSet.getLong( 1 ); String review = resultSet.getString( 2 ); } } } } ); } finally { entityManager.getTransaction().rollback(); entityManager.close(); } }
/** * Test setting timeout that never gets triggered */ @Test public void testNonTriggeredQueryTimeout() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_VERSION_SQL)) { stmt.setQueryTimeout(60); stmt.executeQuery(); ResultSet rs = stmt.getResultSet(); int rowCount = 0; while (rs.next()) { rs.getBytes(1); rowCount++; } assertEquals(1, rowCount); } }
/** * Test setting timeout as zero and executing */ @Test public void testSetQueryTimeoutAsZero() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement(SYS_RANDOM_SQL)) { stmt.setQueryTimeout(0); stmt.executeQuery(); ResultSet rs = stmt.getResultSet(); int rowCount = 0; while (rs.next()) { rs.getBytes(1); rowCount++; } assertEquals(3, rowCount); } }