hi I am implementing rest services using spring 3 and also for data fetching using jdbctemplate.
Currently i have to fetch a record from customer table based upon a customer id passed.
For same i have used : jdbcTemplate.query(SqlQueries.SQL_SELECT_CUSTOMER_ BY_TOKEN, new Object[]{customerToken}, new CustomerExtractor());
CustomerExtractor is a private class implementing ResultSetExtractor
code snippet:
private class CustomerExtractor implements ResultSetExtractor<Customer> {
@Override
public Customer extractData(ResultSet rs) throws SQLException,
DataAccessException {
PS - customer with provided id may or may not exist.
Here when I access rest service using web browser , i don;t get valid customer even if customer id sent as pathVariable is correct.
Upon debugging i found that debug pointer does not go inside the if(rs.next()){} block
There is nothing wrong in query it works fine in mysql workbench.
Also I implemented rest client using apacheHttpClient now when i used this test class to test restservice i got valid response from service
Upon debugging i found that debug pointer goes inside the if(rs.next()){} block
kindly explain why there is such strange behaviour that when accessed via browser i don't get valid response and when tested via test class I get a valid response.
Please use Code tags so that we can read the code you post.
The code you posted seems at this point to be irrelevant to your problem, as you have stated that you are hitting a rest service with a browser and not getting a response. I think a good place to start would be showing us the relevant piece of your controller.
Based on very little information, I would guess that you actually should implement a RowMapper, not a ResultSetExtractor. A ResultSetExtractor would be used if your query has many joins to many tables, so complex queries where you have to build up a big complex object graph. It looks like you are running a query that just goes to your Customer table and returns only results from that one table, where the values from that table map one to one to a Customer object. For those simple queries you should use a RowMapper.
So if you run a query that returns one row, or a query returning 10 rows where each row is mapped to one Customer object, then RowMapper should be used, one big difference is with RowMapper you don't have to loop through the resultset, or check if there is a row or a nextRow.