Atomic Batch
Atomic Batch#
The Altibase JDBC driver not only guarantees the atomicity of batch operations, but also supports fast INSERT operations of bulk data through the Atomic Batch feature.
This section explains how to use the Atomic Batch feature which the Altibase JDBC driver supports.
How to Use Atomic Batch#
In order to use the Atomic Batch feature, you must first create the PreparedStatement object and then cast the object to the AltibasePreparedStatement class type in java programming.
The following method, setAtmoicBatch(), can be used to enable the Atomic Batch feature.
public void setAtomicBatch(boolean aValue) throws SQLException
To confirm whether or not Atomic Batch is set for the PreparedStatement object, call the getAtomicBatch() method as below.
public boolean getAtomicBatch()
Restrictions#
When using the Atomic Batch feature in Altibase, the following restrictions apply:
-
Only supports simple INSERT statements. Consistency for complex INSERT statements or DML statements, such as UPDATE, DELETE, etc., cannot be assured.
-
If a trigger fires with Each Statement as the unit, the trigger fires only once.
-
SYSDATE operates only once.
Example#
...
Connection con = DriverManager.getConnection(aConnectionStr, mProps);
Statement stmt = con.createStatement();
try
{
stmt.execute("Drop table " + TABLE_NAME); } catch (SQLException e) { }
stmt.execute("create table " + TABLE_NAME + "(c1 VARCHAR (1000))");
PreparedStatement sPrepareStmt = con.prepareStatement("insert into " + TABLE_NAME + " values(?)");
((AltibasePreparedStatement)sPrepareStmt).setAtomicBatch(true);
for(int i = 1; i <= MAX_RECORD_CNT; i++)
{
sPrepareStmt.setString(1, String.valueOf(i % 50));
sPrepareStmt.addBatch();
if(i%BATCH_SIZE == 0)
{
sPrepareStmt.executeBatch();
con.commit();
}
}
con.commit();
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
...