import java.sql.*;

public class Test {
    static final String DB_URL = "jdbc:postgresql://localhost/postgres";

    public static void main(String[] args) {
        Connection conn = null;
        // Open a connection
        try {
            conn = DriverManager.getConnection(DB_URL);
            conn.setAutoCommit(false);
            PreparedStatement statement = conn.prepareStatement("INSERT into aa SELECT generate_series(1,10000000) RETURNING a");
			statement.setFetchSize(100);
            ResultSet rs = statement.executeQuery();
			while (rs.next()) {
			}
            conn.commit();
			statement.close();
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (SQLException ee) {
                ee.printStackTrace();
            }
        }
    }
}
