Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Thu, 16 Nov 2006 @ 21:46:06 GMT


     
  <Prev Next>  
<<First
<Prev
Next>
Last>>
 


Subj:   JDBC PerparedStatement.executeBatch() failure -
 
From:   Dan.Haygood

I am having difficulties with the PerparedStatement.executeBatch().

When I call it, it's throwing (full trace below):

     java.lang.ClassCastException:
     com.ncr.teradata.jdbc_4.statemachine.PreparedIndicProtocol

Is this broken?

I read Bob Hahn's post (9/2005)

www.teradataforum.com/teradata/20050913_160911.htm


He says in a subsequent post on the thread, "Prepared statement batch updates require Teradata V2R6 and JDBC 3.2."

Well, I have both of those, so I'm wondering what's wrong.


Thanks,

- Dan


Versions:

     Teradata Database Release V2R.06.01.00.13,
     Teradata Database Version 06.01.00.08b
     Teradata Driver for the JDBC Interface 3.3.0.2
     Java version "1.5.0_08", build b03

I'm class-pathing:

     03/14/2006  12:26 PM             1,686 tdgssconfig.jar
     04/19/2006  05:05 PM           114,908 tdgssjava.jar
     08/17/2006  11:13 AM         1,260,300 terajdbc4.jar

The core code:

     ps = conADW.prepareStatement(
        "insert " + _databaseName_ADW_work
        + ".CustomersToReport values ( ?, ?, ?);"
     );
     ps.setInt(1, 999);
     ps.setInt(2, 777);
     ps.setInt(3, 0);
     ps.addBatch();
     ps.executeBatch();

The full stack trace:

     java.lang.ClassCastException:
     com.ncr.teradata.jdbc_4.statemachine.PreparedIndicProtocol
        at com.ncr.teradata.jdbc_4.statemachine.PreparedBatchStatementSendState.ini
     tSubclassParcels(PreparedBatchStatementSendState.java:95)
        at com.ncr.teradata.jdbc_4.statemachine.StatementSendState.action(Statement
     SendState.java:74)
        at com.ncr.teradata.jdbc_4.statemachine.PreparedBatchStatementSendState.act
     ion(PreparedBatchStatementSendState.java:54)
        at com.ncr.teradata.jdbc_4.statemachine.StatementController.runBody(Stateme
     ntController.java:99)
        at com.ncr.teradata.jdbc_4.statemachine.PreparedBatchStatementController.ru
     n(PreparedBatchStatementController.java:58)
        at com.ncr.teradata.jdbc_4.Statement.executeStatement(Statement.java:253)
        at com.ncr.teradata.jdbc_4.PreparedStatement.executeBatch(PreparedStatement
     .java:112)
        at com.ncr.teradata.jdbc_3.ifjdbc_4.TeraLocalPreparedStatement.executeBatch
     (TeraLocalPreparedStatement.java:320)
        at com.wf.fiu.mt2_poc.MT2_POC.simple(MT2_POC.java:277)
        at com.wf.fiu.mt2_poc.MT2_POC.main(MT2_POC.java:296)

The full code:

     import java.util.*;
     import java.sql.*;

     Public class MyClass {

     static final protected String
     _driverClassName_ADW = "com.ncr.teradata.TeraDriver";

     static final protected String
     _connectionString_ADW = "jdbc:teradata://myhost.com/DBS_PORT=1025/DATABASE=XXX,LOB_SUPPORT=OFF";

     static final protected String
     _username_ADW = "...";

     static final protected String
     _password_ADW = "...";

     static final protected String
     _databaseName_ADW_work = "YYY";

     public static void main(String[] args) {
        Connection conADW = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        Statement s = null;
        try {
           System.out.println("Starting...");
           Class.forName(_driverClassName_ADW);
           conADW = DriverManager.getConnection(

     _connectionString_ADW,_username_ADW,_password_ADW);

           System.out.println("Checking for existing work table.");
           ps = conADW.prepareStatement("select 1 from dbc.Tables "
              + "where DatabaseName = ? and TableName = ?");
           ps.setString(1,_databaseName_ADW_work);
           ps.setString(2,"CustomersToReport");
           rs = ps.executeQuery();
           boolean haveTable = rs.next();
           rs.close(); rs = null;
           ps.close(); ps = null;

           if (haveTable) {
              System.out.println("Dropping existing work table.");
              s = conADW.createStatement();
              s.executeUpdate("drop table "
                 + _databaseName_ADW_work + ".CustomersToReport;");
              s.close(); s = null;
              conADW.commit();
           } else
              System.out.println("No existing work table.");

           System.out.println("Creating work table.");
           s = conADW.createStatement();
           s.executeUpdate(
                "create table " + _databaseName_ADW_work + ".CustomersToReport ("
              + "    cust_co_nbr    integer  not null,"
              + "    cust_nbr       integer  not null,"

              + "    cust_tie_brkr  integer  not null"
              + " )"
              + " unique primary index (cust_co_nbr, cust_nbr, cust_tie_brkr)"
              + ";"
           );
           s.close(); s = null;
           conADW.commit();

           System.out.println("Building batch.");
           ps = conADW.prepareStatement(
              "insert " + _databaseName_ADW_work
              + ".CustomersToReport values ( ?, ?, ?);");
           ps.setInt(1, 999);
           ps.setInt(2, 123);
           ps.setInt(3, 0);
           ps.addBatch();
           ps.setInt(1, 999);
           ps.setInt(2, 777);
           ps.setInt(3, 0);
           ps.addBatch();
           System.out.println("Executing batch.");
           ps.executeBatch();
           System.out.println("Batch executed.");
           ps.clearBatch();
           System.out.println("Done.");
        } catch (Exception x) {
           x.printStackTrace();
        } finally {
           try { if (rs != null) rs.close(); } catch (Exception x) {}
           try { if (s != null) s.close(); } catch (Exception x) {}
           try { if (ps != null) ps.close(); } catch (Exception x) {}
           try { if (conADW != null) conADW.close(); } catch (Exception x) {}
        }
     }
     }


     
  <Prev Next>  
<<First
<Prev
Next>
Last>>
 
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 27 Dec 2016