Results 1 to 3 of 3

Thread: Exception in executing SimpleJdbcCall for fetching rowset/REF cursor

Threaded View

  1. #1
    Join Date
    Jul 2008
    Location
    Mumbai, India
    Posts
    26

    Default Exception in executing SimpleJdbcCall for fetching resultset/REF cursor

    Hi

    I was trying a bit modified usage of this class for a procedure that accepts one input and returns all rows of the table in question.
    some thing similar to the
    The stored procedure being called in my code is as follows

    Code:
    create or replace procedure "GET_EVENT_BY_TITLE"
    (in_title IN VARCHAR2,
    out_id OUT NUMBER,
    out_title OUT VARCHAR2,
    out_location OUT VARCHAR2,
    out_date OUT DATE,
    out_time OUT VARCHAR2)
    is
    begin
    SELECT id, title, location, eventdate, time 
    INTO out_id, out_title, out_location, out_date, out_time
    FROM EVENT where title like in_title;
    end;
    I used the SimpleJdbcCall as follows

    Code:
    public class EventDaoImpl implements EventDao {
    
    	private SimpleJdbcTemplate simpleJdbcTemplate;
    	private JdbcTemplate jdbcTemplate;
    	private SimpleJdbcCall jdbcCall;
    	
    	public EventDaoImpl() {}
    
    	public List<Event> getEventByTitle(String title) {
    
    		jdbcTemplate = new JdbcTemplate(getDataSource());
    		simpleJdbcTemplate = new SimpleJdbcTemplate(getDataSource());
    
    		jdbcCall = new SimpleJdbcCall(jdbcTemplate).withProcedureName(
    				"GET_EVENT_BY_TITLE")
    				.useInParameterNames("IN_TITLE").returningResultSet("events",
    						ParameterizedBeanPropertyRowMapper.newInstance(Event.class));
    
    		SqlParameterSource in = new MapSqlParameterSource().addValue(
    				"IN_TITLE", title);
    
    		Map resultMap = jdbcCall.execute(in);
    
    		List<Event> result = (List<Event>) resultMap.get("events");
    
    		return result;
    
    	}
    
    	public static DataSource getDataSource() {
    		DriverManagerDataSource dataSource = new DriverManagerDataSource();
    		dataSource.setDriverClassName("oracle.jdbc.OracleDriver");
    		dataSource.setUrl("jdbc:oracle:thin:@dev:1521:XE");
    		dataSource.setUsername("appuser");
    		dataSource.setPassword("password");
    
    		return dataSource;
    	}
    
    }
    I get the following exception when in run the class

    Code:
    Exception in thread "main" org.springframework.jdbc.BadSqlGrammarException: CallableStatementCallback; bad SQL grammar [{call GET_EVENT_BY_TITLE(?, ?, ?, ?, ?, ?)}]; nested exception is java.sql.SQLException: ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "APPUSER.GET_EVENT_BY_TITLE", line 10
    ORA-06512: at line 1
    
    	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:111)
    	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:322)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:952)
    	at org.springframework.jdbc.core.JdbcTemplate.call(JdbcTemplate.java:985)
    	at org.springframework.jdbc.core.simple.AbstractJdbcCall.executeCallInternal(AbstractJdbcCall.java:364)
    	at org.springframework.jdbc.core.simple.AbstractJdbcCall.doExecute(AbstractJdbcCall.java:338)
    	at org.springframework.jdbc.core.simple.SimpleJdbcCall.execute(SimpleJdbcCall.java:164)
    	at EventDaoImpl.getEventByTitle(EventDaoImpl.java:39)
    	at RunMain.main(RunMain.java:10)
    Caused by: java.sql.SQLException: ORA-01422: exact fetch returns more than requested number of rows
    ORA-06512: at "APPUSER.GET_EVENT_BY_TITLE", line 10
    ORA-06512: at line 1
    
    	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
    	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
    	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
    	at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:215)
    	at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:954)
    	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
    	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
    	at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3422)
    	at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4394)
    	at org.springframework.jdbc.core.JdbcTemplate$5.doInCallableStatement(JdbcTemplate.java:987)
    	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:936)
    	... 6 more
    Please help.
    Last edited by aadi; Aug 27th, 2008 at 04:18 AM. Reason: corrected typo in heading

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •