Results 1 to 8 of 8

Thread: Batch Update in ASA

  1. #1
    Join Date
    Aug 2004
    Location
    UK
    Posts
    10

    Default Batch Update in ASA

    Hi Guys,
    I am trying to insert records into ASA db using BatchPreparedStatementSetter but for some reason it is failing. the error is

    [JZ0BE: BatchUpdateException: Error occurred while executing batch statement: ASA Error -143: Column '@p0' not found];
    SQL was [INSERT INTO OP_POSITION_DETAILS_SHW ( KEY_POSITION,COMPANY_ID ) VALUES ( ?,? )] for task
    [executing PreparedStatementCallback [org.springframework.jdbc.core.JdbcTemplate$SimpleP reparedStatementCreator@1490eb5]]

    I am not able to figure out how that column name "@po" is constructed although I am specifying in my insert SQL.

    Could any of you tell me please, whats happening and what's needs to be changed.

    Your help / suggestion is much appreciated.

    Regards
    Sanjeev

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    10

    Default ASA batch update - resolved temporarily

    Hi Guys,
    I found partial soultion to my problem.

    The ASA version we are currently using 6.0.3 which does not support Batch Update and hence above exception as batch operation is parameterized. So, I fixed my code temporarily by inserting records individually. .
    some where I read that spring will check with back-end/jdbc driver whether batch update support or not and if not it does a normal insert statement.
    I can't remember where I read, but is this true, If so has any body tried with ASA 6.0 and above ( inclusive)?

    Look forward for information if any body has any thing on this.


    Regards
    Sanjeev

  3. #3
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    from JdbcTemplate.java(Current version in CVS, I did not check if it is in 1.1RC2)
    Code:
    public int[] batchUpdate(String sql, final BatchPreparedStatementSetter pss) throws DataAccessException {
      if (logger.isDebugEnabled()) {
        logger.debug("Executing SQL batch update [" + sql + "]");
      }
      return (int[]) execute(sql, new PreparedStatementCallback() {
        public Object doInPreparedStatement(PreparedStatement ps) throws SQLException {
          int batchSize = pss.getBatchSize();
          DatabaseMetaData dbmd = ps.getConnection().getMetaData();
          try {
            if (dbmd != null && dbmd.supportsBatchUpdates()) {
              for &#40;int i = 0; i < batchSize; i++&#41; &#123;
                pss.setValues&#40;ps, i&#41;;
                ps.addBatch&#40;&#41;;
              &#125;
              return ps.executeBatch&#40;&#41;;
            &#125;
            else &#123;
              int&#91;&#93; rowsAffected = new int&#91;batchSize&#93;;
              for &#40;int i = 0; i < batchSize; i++&#41; &#123;
                pss.setValues&#40;ps, i&#41;;
                rowsAffected&#91;i&#93; = ps.executeUpdate&#40;&#41;;
              &#125;
              return rowsAffected;
            &#125;
          &#125;
          finally &#123;
            if &#40;pss instanceof ParameterDisposer&#41; &#123;
              &#40;&#40;ParameterDisposer&#41; pss&#41;.cleanupParameters&#40;&#41;;
            &#125;
          &#125;
        &#125;
      &#125;&#41;;
    &#125;
    Spring checks with back-end/jdbc driver whether batch update is supported or not and if not it does a normal insert statement.
    I do not know what ASA stands for but I think you can write a small test to check if your db / jdbc driver support batch updates.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    Just something to consider on Spring's JDBC batch update support:

    In the 1.1 codebase there is a new SqlOperation that makes performing batch updates easier than using the batchUpdate method of JdbcTemplate with a PreparedStatementSetter. This operation essentially is a higher-level abstraction on top of JdbcTemplate. The result is some pretty clean code:

    Code:
    BatchSqlUpdate batchUpdater = new MyBatchSqlUpdate&#40;getDataSource&#40;&#41;, "insert into table values&#40;?, ?, ?&#41;"&#41;;
    batchUpdater.update&#40;new Object&#91;&#93; &#123; value1, value2, value3 &#125;;
    batchUpdater.update&#40;new Object&#91;&#93; &#123; value4, value5, value6 &#125;;
    batchUpdater.update&#40;new Object&#91;&#93; &#123; value7, value8, value9 &#125;;
    // etc...
    batchUpdater.flush&#40;&#41;;
    [/code]

  5. #5
    Join Date
    Aug 2004
    Posts
    1,104

    Default Re: ASA batch update - resolved temporarily

    Quote Originally Posted by schiremath
    Hi Guys,
    I found partial soultion to my problem.

    The ASA version we are currently using 6.0.3 which does not support Batch Update and hence above exception as batch operation is parameterized. So, I fixed my code temporarily by inserting records individually. .
    some where I read that spring will check with back-end/jdbc driver whether batch update support or not and if not it does a normal insert statement.
    I can't remember where I read, but is this true, If so has any body tried with ASA 6.0 and above ( inclusive)?

    Look forward for information if any body has any thing on this.
    I tried batch updates with Sybase ASA 9.0.1 which supports batch updates and everything worked fine. I added a DEBUG log statement to JdbcTemplate where we determine if batch updates are supported or not se we can more easily detect what is going on. This is in CVS and will be part of 1.1 final.

    The JdbcTemplate does execute each statement individiually if batch updates are not supported. If this does not work, could you post your code.
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  6. #6
    Join Date
    Aug 2004
    Location
    UK
    Posts
    10

    Default

    Hi All,
    Thank you very much for all your replies.
    When I tried Batch update using ASA 6.0 ( which also supports BachUpdate as per the documentation )
    i get the following error message:

    Code:
    ASA Error -143&#58; Column '@p0' not found&#93;
    I am still using spring 1.1 RC1 and not from CVS head.
    Should I get it from CVS and build or can I
    use the latest RC1 build.?

    Also please note that I tried with jConnect 5.5 / 5.2 driver.
    These drivers support parameterised update and hence I get the above error.


    Thanks and Regards
    Sanjeev

  7. #7
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    I don't think this is a Spring issue. I would create a new database with a new table and try using that just to verify that the batch updates do work.

    I did google for your error and there where a few similar looking issues. Here is one link that might help:
    http://64.233.161.104/search?q=cache...mn+%40p0&hl=en
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  8. #8
    Join Date
    Aug 2004
    Location
    UK
    Posts
    10

    Default

    Hi Thomas,
    First of all thanks for your reply and link. After doing little investigation,
    on ASA doc and google I found out that if using jConnection 5.5 /5.2 driver we can set "LITERAL_PARAMS"
    parameter to enable literal params.
    So, the connection url will be some thing like
    "URL=jdbc:sybase:Tds:ip_address:2638/dbName1?LITERAL_PARAMS=true"

    It works. Batch update works fine in ASA 6.0.3

    I must agree with you that it is nothing to do with Spring.
    Once again thanks for all your help.

    Regards
    Sanjeev

Similar Threads

  1. batch update error using Hibernate 3
    By sbmahs in forum Data
    Replies: 1
    Last Post: Jun 17th, 2006, 01:02 PM
  2. Replies: 1
    Last Post: Jul 3rd, 2005, 04:08 PM
  3. Replies: 1
    Last Post: Apr 29th, 2005, 05:39 PM
  4. Batch update
    By newreaders in forum Data
    Replies: 2
    Last Post: Nov 27th, 2004, 08:33 AM
  5. Force commit in batch update
    By mingshun in forum Data
    Replies: 3
    Last Post: Oct 24th, 2004, 07:09 AM

Posting Permissions

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