Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Cannot run query without RowMapper

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot run query without RowMapper

    Hi,
    I ran to this problem while trying to use JDBCtemplate queryForList(String query) method. This should return List<Map<String, Obkect>>.
    At first my query is simple :
    select * from employee where group_id in (1)
    And it ran perfect.

    After that, I try this :
    select * from employee where group_id in (1,2,3,4,..., 124)
    And it's stuck (It stopped, no error, no exception, even if I debug, it just stopped at queryForList and cannot move down to the code below). However, as I added in to queryForList a RowMapper<Employee>, everything ran smoothly.

    So I have a question, what's wrong with mapping data retrieved manually without RowMapper ?


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Cannot run query without RowMapper

    How do you retrieve the data from your query before applying RowMapper?
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot run query without RowMapper

    I do this :

    String query = select * from employee where group_id in (1,2,3,4,..., 124);
    List<Map<String, Object>> rows = getJdbcTemplate().queryForList(query);
     
    for (Map<String, Object> row : rows) {
    			Employee empl = new Employee();
    			empl.setId(Long.parseLong(row.get("ID").toString()));
    			empl.setGroupId(Long.parseLong(row.get("GROUP_ID").toString()));
    			empl.setVisa((String) row.get("VISA"));
     
    			list.add(empl);
    		}

    and it stuck at queryForList.

    However it ran perfectly for
    query = select * from employee where group_id in (1);

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Cannot run query without RowMapper

    Well, i will suggest you to look at this. Spring JdbcTemplate Querying examples
    Anyone who stops learning is old, whether at twenty or eighty. Anyone who keeps learning stays young. The greatest thing in life is to keep your mind young.

    - Henry Ford

Similar Threads

  1. How to Run PostgreSQL Query in JSP?!
    By Akoori in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: April 15th, 2012, 04:05 PM
  2. JPA many to one/one to many query
    By molleo in forum JDBC & Databases
    Replies: 0
    Last Post: March 25th, 2012, 06:40 AM
  3. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  4. Query
    By amol_kale in forum JDBC & Databases
    Replies: 0
    Last Post: February 18th, 2011, 07:04 AM
  5. SQL query not working
    By mjpam in forum What's Wrong With My Code?
    Replies: 11
    Last Post: September 28th, 2010, 05:15 PM