Results 1 to 5 of 5

Thread: JDBC - getJDBCtemplate with ResultExtractor is slow

  1. #1
    Join Date
    Dec 2010
    Posts
    27

    Question JDBC - getJDBCtemplate with ResultExtractor is slow

    Hi,
    We are migrating our app to Java. Our current query runs fast in our legacy app.
    Now in Using Spring we are running the query like below.

    getJdbcTemplate().query(sqlQuery, rsExtractor);

    in RsExtractor we are doing while(rs.next)-- we are setting results to Value Object.

    This query returns about 5000 rows.... It is very slow compare to legacy app which return in 1 sec. Using Spring JBDCTemplate it takes about 5 sec.

    Any way to tune this or use different api in Spring that is faster. We have to use JDBC.

    Thanks

  2. #2
    Join Date
    Dec 2010
    Posts
    27

    Default

    Can someone please help out here??
    Thanks

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    What is the difference? Is your legacy app also a java app? If not simply executing and returning the results of a query is in general fast, however creation/generation of object instances is slow (especially if you have quite some rows).

    Post some code and configuration (old and new) and how you are testing things.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Dec 2010
    Posts
    27

    Default

    Legacy Code is in Perl....


    In java right we have this simple link. When we click it gets all 5000 rows and displays as a list in drop down.

    Below is our jdbc and resultextractor code.

    1)

    String sql_query = "select name from users";
    displayList = listDAO.queryForObjectName( sql_query, new UserResultSetExtractor());

    2) Than in the queryForObjectFromName method we call our jdbctemplate.

    return getJdbcTemplate().query(sqlQuery, rsExtractor);

    3) Our UserResultSetExtractor class extends extends AbstractResultSetExtractor and code it contains.

    protected Object processResultSet(ResultSet rs) throws SQLException,DataAccessException {

    List userNameList = new ArrayList();

    if(rs.isBeforeFirst() && !rs.isAfterLast()) {
    UserVO userList = null;
    logger.info("Fetching records");
    while(rs.next()) {
    userList = new UserVO();
    userList.setUserId(rs.getString("USERNAME"));
    userNameList .add(userList);
    }
    }
    return userNameList ;
    }


    4) Than we just display the list using struts2 ui tags.

    Thanks

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Please use [ code][/code ] tags when posting code.

    Legacy Code is in Perl....
    So basically is is comparing apples and oranges (that is IMHO ofcourse).

    For starters I would use a RowMapper instead of a ResultSetExtractor that way spring does the looping. Also is the looping slow, the query execution? Next to that are you using a connection pool or are you using a DriverManagerDataSource (which creates a new connection to the database each time it needs one!).

    Also is it really necessary to convert it to a list of UserVO? If you are only getting/using the username, why not simply return everything as a string?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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