Note that there are some explanatory texts on larger screens.

plurals
  1. POJava JDBC - prepared statement for bulk insertion using merge sort
    primarykey
    data
    text
    <p>I am using JDBC prepared statement for bulk insertion. I am calling <code>ps.execute()</code> method. If it fails then i am calling a method where i am passing the list of parameters and the prepared statement. I am using <code>merge sort technique to divide the list</code> and then trying to insert the records, but not successfull. </p> <p>Here is my code;</p> <p>from executePrepareStatement method i am calling </p> <pre><code>this.executeInsertStatement(query, myCollection, 0, myCollection.size()); </code></pre> <p>// executeInsertStatement method</p> <pre><code>public void executeInsertStatement1(String query, List myCollection, int sIndx, int eIndx) throws DBException,SQLException { int startIndx = sIndx, endIndx = eIndx, mid = 0; try { try{ if(conn.isClosed()) new DataService(CoreConstants.TARGET); } catch (Exception e) { } if(startIndx &gt;= endIndx) { return; } conn.setAutoCommit(false); if (query != null) { mid = (startIndx + endIndx) / 2; ps = conn.prepareStatement(query); executeInsertStatement(query, myCollection, startIndx, mid); executeInsertStatement(query, myCollection, mid+1, endIndx); //int end_low = mid; //int start_high = mid + 1; if(mid &lt; endIndx) endIndx = mid; for (int i = 0; i &lt; endIndx; i++) { List list = (List) myCollection.get(i); int count = 1; for (int j = 0; j &lt; list.size(); j++) { if(list.get(j) instanceof Timestamp) { ps.setTimestamp(count, (Timestamp) list.get(j)); } else if(list.get(j) instanceof java.lang.Character) { ps.setString(count, String.valueOf(list.get(j))); } else { ps.setObject(count, list.get(j)); } count++; } try { ps.execute(); } catch (Exception e) { rollback(); } } } } catch (Exception e) { rollback(); } finally{ try { if (ps != null) { ps.close(); ps = null; } } catch (Exception ex) { } } } </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload