String sql;
PreparedStatement ps;
System.out.println("please wait...");
Date dt1 = new Date();
sql = "INSERT INTO TABLE(COLUMNS) VALUES (?,?,?,?,?,?,?,?,?)";
ps = conn.prepareStatement(sql);
for(int i=0;i<htlist.size();i++) //htlist.size()
{
HanaTrace ht = htlist.get(i);
ps.setString(1,ht.getId1());
...
ps.addBatch(); // << key!!!
if(i % 1000 == 0)
System.out.println(i);
}
ps.executeBatch();// << key!!!
Here is an update:
When putting too many rows into Batch, the Batch will meet the limit.
Thus, you need to executeBatch Sequentially.
For example:
for(int i=0;i<j;i++)
{
for(int k=1;k<=numberofcol;k++)
{
ps.setInt(k, r.nextInt(5000));
}
ps.addBatch();
if(i % 5000 == 0)
{
ps.executeBatch();
ps.clearBatch();
}
}
ps.executeBatch();
ps.clearBatch();