Announcement Announcement Module
Collapse
No announcement yet.
multiple cursor with spring batch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • multiple cursor with spring batch

    Hi All,

    I am learning spring batch and have a problem,
    I am trying to do the same as the following with spring batch.
    How can I get it done?
    NOTE:It has two cursors in one step.

    Code:
    con = dataSource.getConnection();
    stmt = con.createStatement();
    
    res1 = stmt.executeQuery(sql1);
    while (res1.next()) {
        
    }
    /* write data to file1 */
    
    res2 = stmt.executeQuery(sql2);
    while (res2.next()) {
        
    }
    /* write data to file2 */
    Thanks

  • #2
    Unless I'm missing something, this scenario would be easily implemented using two steps, one for each cursor, each using the JdbcCursorItemReader. Keep in mind, that the steps run through all of the input before moving on to the next step. Meaning, step1 reads and writes until there's nothing left to read, then the second step starts.

    Comment


    • #3
      lucasward

      Thanks for your reply.
      I'm trying to solve it using one step.
      Is that possible with spring batch?

      Comment


      • #4
        If you're reading from two separate queries, it really makes sense to keep the processing separate. Step 1 processes query 1. Step 2 processes query 2. Unless you need to process both queries together, in which case a JOIN would be appropriate, but still that's just one SQL execution.

        If that doesn't seem to work for you, perhaps you could explain why you need two queries in one step.

        Comment


        • #5
          There is something worng with my code.
          I changed it:

          Code:
          con = dataSource.getConnection();
          stmt = con.createStatement();
          
          res1 = stmt.executeQuery(sql1);
          while (res1.next()) {
              
          }
          /* write data to table1 */
          
          res2 = stmt.executeQuery(sql2);
          while (res2.next()) {
              
          }
          /* write data to table2 */
          My meaning is when the code get res2 was failure, then the operation of writing table1 should be rollback.
          I don`t know how to achieve it.

          Comment

          Working...
          X