skip to main content
Designing and coding the IP : Bulk insert : Bulk insert processing in Java : Example
 

Example

To process the bulk insert statement:
1. Obtain the first row to be inserted using dam_getFirstInsertRow.
2. Obtain the first value set using dam_getFirstValueSet and pass the obtained row element (DAM_HROWELEM) to dam_getBulkValueToSet.
Use dam_getColToSet to obtain details about the column.
hRowElem = jdam.dam_getFirstValueSet(dam_hstmt, hrow);
if(hRowElem == 0) return IP_SUCCESS;
while(hRowElem != 0)
{
hcol = jdam.dam_getColToSet(hRowElem);
jdam.dam_describeCol(hcol, null, sColName, iXoType, null);
objects = jdam.dam_getBulkValueToSet(dam_hstmt, hRowElem, iRowCount);
/*Add code to retrieve the values and to save them*/
jdam.dam_freeBulkValue(objects);
hRowElem = jdam.dam_getNextValueSet(dam_hstmt);
}
3. Call dam_getBulkValueToSet that returns an array of objects (column values) and the number of rows to be inserted for the specified row element.
You must save the bulk information received from dam_getBulkValueToSet.
4. Obtain the next value set using dam_getNextValueSet. If the value returned is not null, repeat Steps 3 and 4 until all the values are retrieved.
5. For each row, based on the bulk information returned, retrieve the column values from the object array and type cast values to the required data type based on the type mapping, and then build the rows. Refer to Mapping SQL datatypes to Java datatypes for more information on type casting.
Note:Index the array to obtain any specific objects, while building the rows.
6. Insert rows to the data source and mark the row insert status of each row using the byte array returned by dam_getBulkRowStatusArray.
If a row is inserted successfully, its status is marked as DAM_ROW_SUCCESS. If the row is not inserted successfully, the status is marked as DAM_ROW_ERROR.
7. Free the object array that is returned by dam_getBulkValueToSet using dam_freeBulkValue.
The following code snippet illustrates how to obtain the object arrays from the columns.
while(hRowElem != 0)
{
hcol = jdam.dam_getColToSet(hRowElem);
...
/* Add code to save or store the object array to use it while building rows*/
 
objects = jdam.dam_getBulkValueToSet(dam_hstmt, hRowElem, iRowCount);
 
...
/* Add code to save or store the object array to use it while building rows*/
 
jdam.dam_freeBulkValue(objects);
hRowElem = jdam.dam_getNextValueSet(dam_hstmt);
}