@@ -102,16 +102,14 @@ String getInsertQuery(IloTupleSchema schema, String table) {
102102 return query ;
103103 }
104104
105- void updateValues (IloTuple tuple , IloTupleSchema schema ,
106- IloOplTupleSchemaDefinition tupleSchemaDef , PreparedStatement stmt ) throws SQLException {
107- for (int i = 0 ; i < schema .getSize (); i ++) {
105+ void updateValues (IloTuple tuple , PreparedStatement stmt , Type [] columnType ) throws SQLException {
106+ for (int i = 0 ; i < columnType .length ; i ++) {
108107 int index = i +1 ; // index in PreparedStatement
109- Type columnType = tupleSchemaDef .getComponent (i ).getElementDefinitionType ();
110- if (columnType == Type .INTEGER )
108+ if (columnType [i ] == Type .INTEGER )
111109 stmt .setInt (index , tuple .getIntValue (i ));
112- else if (columnType == Type .FLOAT )
110+ else if (columnType [ i ] == Type .FLOAT )
113111 stmt .setDouble (index , tuple .getNumValue (i ));
114- else if (columnType == Type .STRING )
112+ else if (columnType [ i ] == Type .STRING )
115113 stmt .setString (index , tuple .getStringValue (i ));
116114 }
117115 }
@@ -149,14 +147,17 @@ void customWrite(String name, String table) {
149147 try {
150148 IloOplElementDefinition tupleDef = _def .getElementDefinition (schema .getName ());
151149 IloOplTupleSchemaDefinition tupleSchemaDef = tupleDef .asTupleSchema ();
150+ final Type [] columnType = new Type [schema .getSize ()];
151+ for (int i = 0 ; i < columnType .length ; ++i )
152+ columnType [i ] = tupleSchemaDef .getComponent (i ).getElementDefinitionType ();
152153
153154 conn .setAutoCommit (false ); // begin transaction
154155 String psql = getInsertQuery (schema , table );
155156 PreparedStatement pstmt = conn .prepareStatement (psql );
156157 // iterate the set and create the final insert statement
157158 for (java .util .Iterator it1 = tupleSet .iterator (); it1 .hasNext ();) {
158159 IloTuple tuple = (IloTuple ) it1 .next ();
159- updateValues (tuple , schema , tupleSchemaDef , pstmt );
160+ updateValues (tuple , pstmt , columnType );
160161 pstmt .executeUpdate ();
161162 }
162163 conn .commit ();
@@ -175,4 +176,4 @@ void customWrite(String name, String table) {
175176 }
176177 }
177178 }
178- }
179+ }
0 commit comments