I changed the code in the BankTest example from
private void prepareResultSet()
{
StatementResultSetHandler statementHandler = getJDBCMockObjectFactory().getMockConnection().getStatementResultSetHandler();
MockResultSet result = statementHandler.createResultSet();
result.addRow(new Integer {new Integer(10000)});
statementHandler.prepareGlobalResultSet(result);
}
to the following
private void prepareResultSet()
{
PreparedStatementResultSetHandler statementHandler = getJDBCMockObjectFactory().getMockConnection().getPreparedStatementResultSetHandler();
MockResultSet result = statementHandler.createResultSet();
result.addRow(new Integer {new Integer(10000)});
statementHandler.prepareResultSet("select balance from account where id=1",result);
}
This was done the compensate for the change in the Bank class isValid method where I select statement to a preparedStatement type
PreparedStatement statement = null;
ResultSet result = null;
statement = connection.prepareStatement("select balance from account where id=" + sourceId);
result = statement.executeQuery();
whereas the original code looked like
Statement statement = null;
ResultSet result = null;
statement = connection.createStatement();
result = statement.executeQuery("select balance from account where id=" + sourceId);
I thought I had made the correct changes so the test would run successfully but upon debugging I discovered that the resultSet is always null after execution.
Any help in where I have gone wrong would be appreciated.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I'm not able to reproduce this. Your code is fine and it works. The BankTest.testWrongId() is not running, because you did not change prepareEmptyResultSet(). But the other two test methods do run.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for the quick reply, I managed to figure out what I was doing wrong by looking up some more example on the internet it seems that I have to switch
statementHandler.prepareResultSet("select balance from account where id=1",result);
with
statementHandler.prepareGlobalResultSet(result);
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I changed the code in the BankTest example from
private void prepareResultSet()
{
StatementResultSetHandler statementHandler = getJDBCMockObjectFactory().getMockConnection().getStatementResultSetHandler();
MockResultSet result = statementHandler.createResultSet();
result.addRow(new Integer {new Integer(10000)});
statementHandler.prepareGlobalResultSet(result);
}
to the following
private void prepareResultSet()
{
PreparedStatementResultSetHandler statementHandler = getJDBCMockObjectFactory().getMockConnection().getPreparedStatementResultSetHandler();
MockResultSet result = statementHandler.createResultSet();
result.addRow(new Integer {new Integer(10000)});
statementHandler.prepareResultSet("select balance from account where id=1",result);
}
This was done the compensate for the change in the Bank class isValid method where I select statement to a preparedStatement type
PreparedStatement statement = null;
ResultSet result = null;
statement = connection.prepareStatement("select balance from account where id=" + sourceId);
result = statement.executeQuery();
whereas the original code looked like
Statement statement = null;
ResultSet result = null;
statement = connection.createStatement();
result = statement.executeQuery("select balance from account where id=" + sourceId);
I thought I had made the correct changes so the test would run successfully but upon debugging I discovered that the resultSet is always null after execution.
Any help in where I have gone wrong would be appreciated.
Sorry, I'm not able to reproduce this. Your code is fine and it works. The BankTest.testWrongId() is not running, because you did not change prepareEmptyResultSet(). But the other two test methods do run.
Thanks for the quick reply, I managed to figure out what I was doing wrong by looking up some more example on the internet it seems that I have to switch
statementHandler.prepareResultSet("select balance from account where id=1",result);
with
statementHandler.prepareGlobalResultSet(result);