tags:

views:

59

answers:

1

Hello!

I am just getting started with Spring (MVC,Webflow etc etc) and I am trying to write my own small web application. As a database I am using Apache Derby which I set up though the Eclipse Database Developer plug-ins.

Now my problem: Everytime I fire queries through the JDBCTemplate I get an "Invalid cursor state" exception at runtime. These are queries that work when they are manually tested (aka ask the database through the SQL Scrapbook.

This is my simplest DAO method:

public List<Player> getAllPlayers() {
    JdbcTemplate select = new JdbcTemplate(dataSource);
    List<Player> result = select.query(
                        "SELECT ID , Name , TeamID " +
                        "FROM PLAYERS " , new PlayerExtractor());
    return result;
}

And this is the corresponging ResultSetExtractor:

@Override
public Object extractData(ResultSet rs) throws SQLException,
        DataAccessException {

    Player player = new Player();
    player.setId(Integer.valueOf(rs.getString(1)));
    player.setName(rs.getString(2));
    TeamDAO t_dao = new TeamDAOImpl();
    Team team = t_dao.getTeamByKey( Integer.valueOf(rs.getString(3)) );
    player.setTeam(team);

    return player;
}

As soon as rs.getString(1) the "invalid cursor state". What is the problem? I have a feeling that it is a configuration problem..

Here is my JDBC configuration in my ApplicationContext:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.apache.derby.jdbc.Driver169"/>
<property name="url" value="jdbc:derby:C:\Dokumente und Einstellungen\araptarc\MyDB"/>
<property name="username" value="APP"/>
<property name="password" value="test"/>

Any ideas?

Thanks!

+1  A: 

I see you specified value="org.apache.derby.jdbc.Driver169". Are you trying to run in a J2ME configuration? Can you set up a test where you run your application using an embedded Derby configuration with a full JDK, and see if your program works correctly in that case?

Bryan Pendleton