Quantcast
Channel: SCN : Discussion List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 5653

Why do I get a problem if I set a batch size for prepared statement to 1?

$
0
0

Hi,

Is it a bug?

I use the following pseudo code to send an array of data records to one database:

 

...  
var myDataRecords = [...];                  // array with data records  
var myInsertQuery = 'INSET INTO ...';  
prepSt = conn.prepareStatement(myInsertQuery);  
if (myDataRecords.length > 0){       prepSt.setBatchSize(myDataRecords.length);       for(var i = 0; i < myDataRecords.length; i++){            prepSt.setInt(1, myDataRecords[i].dataField_1);            prepSt.setString(2, myDataRecords[i].dataField_2);            ...            prepSt.setString(n, myDataRecords[i].dataField_n);            prepSt.addBatch();       }       prepSt.executeBatch();       
}  
prepSt.close();  
...  

It works fine but if the data record array has only one record this code throws exception at addBatch():

"PreparedStatement.addBatch: bulk insert not enabled".

Is a "batching" with a batch size = 1 a special case?  The special cases make a code ugly. .


Viewing all articles
Browse latest Browse all 5653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>