The Java test case at the end of the post count the log file sync waits and user commits for inserting 10,000 rows into a single column table (create table x (a number)). The table below shows summary for running test with auto commit on and off. The database used was a standard edition 11.2.0.4.
| Measurement | Auto Commit On | Auto Commit Off |
| Log File Sync Waits | 10000 | 1 |
| User commits | 10000 | 1 |
| Elapsed Time (sec) | 50 | 23 |
Below java code could be used for testing for other DML events.
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import oracle.ucp.jdbc.PoolDataSource;
import oracle.ucp.jdbc.PoolDataSourceFactory;
public class CMTest {
private final HashMap valueMap = new HashMap<>();
private final PoolDataSource ds;
public CMTest() throws SQLException {
ds = PoolDataSourceFactory.getPoolDataSource();
ds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource");
ds.setUser("asanga");
ds.setPassword("xxx");
ds.setURL("jdbc:oracle:thin:@192.168.0.66:1521:std11g4");
}
public Connection getConnection() throws SQLException {
return ds.getConnection();
}
public static void main(String[] args) throws SQLException {
CMTest test = new CMTest();
Connection con = test.getConnection();
con.setAutoCommit(false); // comment to make auto auto commit true
test.printStat(con, 1);
test.runTest(con);
test.printStat(con, 2);
}
public void printStat(Connection con, int i) throws SQLException {
String SQL = "select st.name,s.value from v$statname st, v$sesstat s where st.STATISTIC#=s.STATISTIC# and s.sid=SYS_CONTEXT ('USERENV', 'SID') and st.name='user commits' "
+ "union "
+ "select e.event,TOTAL_WAITS from v$session_event e where e.event='log file sync' and e.sid=SYS_CONTEXT ('USERENV', 'SID')";
// + "union "
// + "select e.event,TIME_WAITED_MICRO from v$session_event e where e.event='log file sync' and e.sid=SYS_CONTEXT ('USERENV', 'SID')";
PreparedStatement pr = con.prepareStatement(SQL);
ResultSet rs = pr.executeQuery();
while (rs.next()) {
if (i == 1) {
valueMap.put(rs.getString(1), rs.getInt(2));
} else {
Integer x = valueMap.get(rs.getString(1));
x = (x == null) ? 0 : x;
System.out.println(rs.getString(1) + " " + (rs.getInt(2) - x));
}
}
rs.close();
pr.close();
}
public void runTest(Connection con) throws SQLException {
String sql = "insert into x values (?)";
// String sql = "delete from x where a = ?";
PreparedStatement pr = con.prepareStatement(sql);
for (int i = 0; i < 10000; i++) {
pr.setInt(1, i);
pr.execute();
}
con.commit();
pr.close();
}
} Related Postsjava.sql.SQLException: Could not commit with auto-commit set on When Using 12c JDBC Driver

