public ResultSet getResultSet() throws SQLException { return cstmt.getResultSet(); }
if (resultSetParameters != null && resultSetParameters.size() > rsIndex) { SqlReturnResultSet declaredRsParam = (SqlReturnResultSet) resultSetParameters.get(rsIndex); returnedResults.putAll(processResultSet(cs.getResultSet(), declaredRsParam)); rsIndex++; logger.trace("Added default SqlReturnResultSet parameter named '" + rsName + "'"); returnedResults.putAll(processResultSet(cs.getResultSet(), undeclaredRsParam)); rsIndex++;
@Override public ResultSet getResultSet(CallableStatement ps) throws SQLException { boolean isResultSet = ps.execute(); // This assumes you will want to ignore any update counts while (!isResultSet && ps.getUpdateCount() != -1) { isResultSet = ps.getMoreResults(); } return ps.getResultSet(); } }
@Override public ResultSet getResultSet(CallableStatement ps) throws SQLException { boolean isResultSet = ps.execute(); while ( !isResultSet && ps.getUpdateCount() != -1 ) { isResultSet = ps.getMoreResults(); } return ps.getResultSet(); }
@Override public ResultSet getResultSet(CallableStatement cs) throws SQLException { boolean isResultSet = cs.execute(); while ( !isResultSet && cs.getUpdateCount() != -1 ) { isResultSet = cs.getMoreResults(); } return cs.getResultSet(); }
@Override public ResultSet getResultSet(CallableStatement ps) throws SQLException { boolean isResultSet = ps.execute(); // This assumes you will want to ignore any update counts while ( !isResultSet && ps.getUpdateCount() != -1 ) { isResultSet = ps.getMoreResults(); } return ps.getResultSet(); }
@Override public ResultSet getResultSet(CallableStatement ps) throws SQLException { boolean isResultSet = ps.execute(); // This assumes you will want to ignore any update counts while ( !isResultSet && ps.getUpdateCount() != -1 ) { isResultSet = ps.getMoreResults(); } // You may still have other ResultSets or update counts left to process here // but you can't do it now or the ResultSet you just got will be closed return ps.getResultSet(); }
rs = callableStatement.getResultSet();
rs = stmt.getResultSet(); try { st.onAfter(conn, rs, null); rs = stmt.getResultSet(); try { if (rs != null)
rs = cstmt.getResultSet();
given(callableStatement.getResultSet()).willReturn(resultSet1, resultSet2); given(callableStatement.getMoreResults()).willReturn(true, false, false); given(callableStatement.getUpdateCount()).willReturn(-1, -1, 0, -1);
@Test @SuppressWarnings("unchecked") public void testStoredProcedureSkippingUndeclaredResults() throws Exception { ResultSet resultSet = mock(ResultSet.class); given(resultSet.next()).willReturn(true, true, false); given(resultSet.getString(2)).willReturn("Foo", "Bar"); given(callableStatement.execute()).willReturn(true); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getResultSet()).willReturn(resultSet); given(callableStatement.getMoreResults()).willReturn(true, false); given(callableStatement.getUpdateCount()).willReturn(-1, -1); given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}") ).willReturn(callableStatement); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.setSkipUndeclaredResults(true); StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped( jdbcTemplate); Map<String, Object> res = sproc.execute(); assertEquals("incorrect number of returns", 1, res.size()); List<String> rs1 = (List<String>) res.get("rs"); assertEquals(2, rs1.size()); assertEquals("Foo", rs1.get(0)); assertEquals("Bar", rs1.get(1)); verify(resultSet).close(); }
@Test @SuppressWarnings("unchecked") public void testStoredProcedureWithResultSetMapped() throws Exception { ResultSet resultSet = mock(ResultSet.class); given(resultSet.next()).willReturn(true, true, false); given(resultSet.getString(2)).willReturn("Foo", "Bar"); given(callableStatement.execute()).willReturn(true); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getResultSet()).willReturn(resultSet); given(callableStatement.getMoreResults()).willReturn(false); given(callableStatement.getUpdateCount()).willReturn(-1); given(connection.prepareCall("{call " + StoredProcedureWithResultSetMapped.SQL + "()}") ).willReturn(callableStatement); StoredProcedureWithResultSetMapped sproc = new StoredProcedureWithResultSetMapped(dataSource); Map<String, Object> res = sproc.execute(); List<String> rs = (List<String>) res.get("rs"); assertEquals(2, rs.size()); assertEquals("Foo", rs.get(0)); assertEquals("Bar", rs.get(1)); verify(resultSet).close(); }
@Before public void setup() throws Exception { this.connection = mock(Connection.class); this.dataSource = mock(DataSource.class); this.preparedStatement = mock(PreparedStatement.class); this.statement = mock(Statement.class); this.resultSet = mock(ResultSet.class); this.template = new JdbcTemplate(this.dataSource); this.callableStatement = mock(CallableStatement.class); given(this.dataSource.getConnection()).willReturn(this.connection); given(this.connection.prepareStatement(anyString())).willReturn(this.preparedStatement); given(this.preparedStatement.executeQuery()).willReturn(this.resultSet); given(this.preparedStatement.executeQuery(anyString())).willReturn(this.resultSet); given(this.preparedStatement.getConnection()).willReturn(this.connection); given(this.statement.getConnection()).willReturn(this.connection); given(this.statement.executeQuery(anyString())).willReturn(this.resultSet); given(this.connection.prepareCall(anyString())).willReturn(this.callableStatement); given(this.callableStatement.getResultSet()).willReturn(this.resultSet); }
@Test public void testStoredProcedureWithResultSet() throws Exception { ResultSet resultSet = mock(ResultSet.class); given(resultSet.next()).willReturn(true, true, false); given(callableStatement.execute()).willReturn(true); given(callableStatement.getUpdateCount()).willReturn(-1); given(callableStatement.getResultSet()).willReturn(resultSet); given(callableStatement.getUpdateCount()).willReturn(-1); given(connection.prepareCall("{call " + StoredProcedureWithResultSet.SQL + "()}") ).willReturn(callableStatement); StoredProcedureWithResultSet sproc = new StoredProcedureWithResultSet(dataSource); sproc.execute(); assertEquals(2, sproc.getCount()); verify(resultSet).close(); }
@Test public void testStoredProcedureResultSet() throws SQLException { if( "Oracle".equals(db)) { // Oracle does not support returning a resultset from a store proc via CallableStatement.getResultSet() return; } P6LogOptions.getActiveInstance().setExcludecategories("debug,info,result"); this.clearLogEntries(); // execute the statement String query = "{call test_proc_rs(?)}"; CallableStatement call = connection.prepareCall(query); call.setString(1, "a"); call.execute(); ResultSet rs = call.getResultSet(); if( rs == null ) { // HSQLDB requires you to call ResultSet.getMoreResults() before accessing the resultset. call.getMoreResults(); rs = call.getResultSet(); } while(rs.next()) { rs.getString("name"); rs.getInt("id"); } rs.close(); call.close(); // verify that the result set was logged assertTrue(getLastLogEntry().contains("resultset")); }
/** * Get the last result set, with the option of not wrapping it in a * {@link DelegatingResultSet}, which is the default. */ protected ResultSet getResultSet(boolean wrap) throws SQLException { ResultSet rs; if (_del != null) rs = _del.getResultSet(false); else rs = _stmnt.getResultSet(); return wrapResult(wrap, rs); }
public ResultSet getResultSet() throws SQLException { Profiler profiler = _profilerPoint.start(); try { return _callableStatement.getResultSet(); } finally { profiler.finish(); } }
/** * {@inheritDoc} */ @Override public ResultSet getResultSet() { try { return getExecutor().getStatement().getResultSet(); } catch (SQLException ex) { throw new SQLRuntimeException(ex); } }
public ResultSet getResultSet(CallableStatement ps) throws SQLException { boolean isResultSet = ps.execute(); // This assumes you will want to ignore any update counts while (!isResultSet && ps.getUpdateCount() != -1) { isResultSet = ps.getMoreResults(); } ResultSet rs = ps.getResultSet(); // You may still have other ResultSets or update counts left to process here // but you can't do it now or the ResultSet you just got will be closed return rs; }