Results 1 to 3 of 3

Thread: Query the database after having read a row of a file

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Posts
    24

    Default Query the database after having read a row of a file

    Hello,

    I am currently reading a lot of examples and documentation but I really don't understand how to solve the following problem.
    SO far, I configured Spring Batch to read data from an input file, parse and write to an output file the parsed data using a regular expression during the read phase.
    But I need to query the database and get further data, before writing to the output file.

    I've seen many approaches but I am still not convinced on what is the right one because, I've tried to use a processor to try to build a query to the database, or using something like JDBCTemplate with RowMapper for JdbcCursorItemReader etc.

    To be honest, I don't understand if I have to implement my own ItemReader in this case or if it is sufficient to configure the xml spring batch file.

    Note that, for each row of the file I am reading I get a String. Such String should be used to query the database, using a PreparedStatement (for instance), since I have something like "select name, age from person where name = ?".

    Even reading this, I am still confused, because it shows examples where it uses "this.jdbcTemplate.queryForInt(...)" and I don't understand where to place such code.

    Could somebody help me please?

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,695

    Default

    You need a processor (as I already mentioned in the other posts) and the logic to convert the string to something else should go in there (in this case your query for the database). How you do that is up to you but I would recommend using JdbcTemplate.
    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

  3. #3
    Join Date
    Jul 2012
    Posts
    24

    Default

    Perfect! Thank you so much. I will use the processor then. I've actually tried to use a sort of "stub" in the processor to set the field of my object, but I didn't know if there was a better way to query the DB out of a processor.
    I will let you know just in case of futher problems. Thanks.

Posting Permissions

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