Hi,
does HXTT ACCESS support batch insertion (PreparedStatement.addBatch and PreparedStatement.executeBatch)?
Example: http://viralpatel.net/blogs/batch-insert-in-java-jdbc/
Best regards
Patrick
|
No issue. HXTT Access supports batch insert, transaction, linked table, and so on.
|
Thank you for the quick answer!
What about the option Statement.RETURN_GENERATED_KEYS in batch insertions?
I observed this for a table TEST with columns 'ID INT AUTO_INCREMENT' and 'name VARCHAR(100)':
// single insert returns auto-generated ID
final PreparedStatement stmt = connection.prepareStatement("insert into TEST (Name) values (?)", Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, "x");
stmt.execute();
final ResultSet rs = stmt.getGeneratedKeys();
final List ids = new ArrayList();
while (rs.next()) {
ids.add(rs.getInt(1));
}
stmt.close();
System.out.println("Generated single ID: " + ids); // prints: [2]
// batch insert does NOT return auto-generated IDs
final PreparedStatement stmt2 = connection.prepareStatement("insert into TEST (Name) values (?)", Statement.RETURN_GENERATED_KEYS);
for (int i = 0; i < 3; i++) {
stmt2.setString(1, "x" + i);
stmt2.addBatch();
}
stmt2.executeBatch();
final ResultSet rs2 = stmt2.getGeneratedKeys();
final List ids2 = new ArrayList();
while (rs2.next()) {
ids2.add(rs2.getInt(1));
}
stmt2.close();
System.out.println("Generated batch IDs: " + ids2); // prints: []
Did I miss anything?
How is it possible to retrieve auto-generated IDs via batch insert?
|
2017-06-30 PreparedStatement.executeBatch suupports RETURN_GENERATED_KEYS.
|