My appication uses Java + jOOQ + H2DB.
I have created two Threads
to continue execution.
Thread 1: Insert records continuously into table A
Thread 2: Select limit of 10000 consecutive records from table A
When I run my application, sometimes the org.h2.jdbc.JdbcSQLSyntaxErrorException
is thrown,
SQL statements have been changed by some characters PUBLIC.SCENAR ऀ☀䙉O_EXECUTE_LOG
org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "PUBLIC.SCENAR ऀ☀䙉O_EXECUTE_LOG.TOTAL_RUNNING_TIME" not found; SQL statement:
select "PUBLIC"."SCENARIO_EXECUTE_LOG"."LOG_SEQ", "PUBLIC"."SCENARIO_EXECUTE_LOG"."USER_ID", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_DIV", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_SCENARIO_ID", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_START_TIME_UTC", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_END_TIME_UTC", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_START_TIME_LOCAL", "PUBLIC"."SCENARIO_EXECUTE_LOG"."EXECUTE_END_TIME_LOCAL", "PUBLIC"."SCENAR ऀ☀䙉O_EXECUTE_LOG"."TOTAL_RUNNING_TIME", "PUBLIC"."SCENARIO_EXECUTE_LOG"."LOG_FOLDER_NAME", "PUBLIC"."SCENARIO_EXECUTE_LOG"."RESULT_DIV" from "PUBLIC"."SCENARIO_EXECUTE_LOG" where "PUBLIC"."SCENARIO_EXECUTE_LOG"."LOG_SEQ" = cast(? as int) for [42122-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.expression.ExpressionColumn.getColumnException(ExpressionColumn.java:176)
at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:158)
at org.h2.command.dml.Select.prepare(Select.java:1245)
at org.h2.command.Parser.prepareCommand(Parser.java:689)
at org.h2.engine.Session.prepareLocal(Session.java:627)
at org.h2.server.TcpServerThread.process(TcpServerThread.java:270)
at org.h2.server.TcpServerThread.run(TcpServerThread.java:175)
at java.base/java.lang.Thread.run(Thread.java:844)
Rather, it is PUBLIC.SCENARIO_EXECUTE_LOG
If I only run thread 1 or thread 2 then this error does not arise
From where did this error arise?
UPDATE:
Helper class
private static Connection h2Connection;
private static DSLContext dslContext;
private static Server server;
public static DSLContext getDSLContext() throws Exception {
if (dslContext == null) {
dslContext = new DefaultDSLContext(getConnection(), SQLDialect.H2, settings);
}
return dslContext;
}
private static Connection getConnection() throws Exception {
if (h2Connection == null) {
Class.forName("org.h2.Driver");
String url = String.format("jdbc:h2:tcp://localhost/%s;", (DB_PATH.isEmpty() ? OUTPUT_PATH + folderPath + H2DB_PATH : DB_PATH)) +
String.format("USER=%s;", USER_NAME) +
String.format("PASSWORD=%s;", PASSWORD);
System.setProperty("java.net.useSystemProxies", "false");
server = Server.createTcpServer("-tcpAllowOthers").start();
System.setProperty("java.net.useSystemProxies", "true");
try {
h2Connection = new JdbcConnection(url, new Properties());
return h2Connection;
} catch (Exception ex) {
log.error("Error fetching connection", ex);
throw ex;
}
}
return h2Connection;
}
Main class
Thread insertExecuteLog = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
Random random = new Random();
scenarioExecuteLogRecordInsert.setLogSeq(random.nextInt(10000000 - 4000000) + 4000000);
JooqScenarioExecuteLogHelper.insertExecuteLog(scenarioExecuteLogRecordInsert);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
});
Thread getExecuteLog = new Thread(() -> {
while (!Thread.currentThread().isInterrupted()) {
try {
ScenarioExecuteLogRecord[] listScenarioExecuteLog2 = JooqScenarioExecuteLogHelper.getListScenarioExecuteLog();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
});
insertExecuteLog.start();
getExecuteLog.start();
SQL
public static ScenarioExecuteLogRecord[] getListScenarioExecuteLog(){
DSLContext dslContext = JooqRpaSysDBHelper.getDSLContext();
return dslContext.selectFrom(SCENARIO_EXECUTE_LOG)
.orderBy(SCENARIO_EXECUTE_LOG.LOG_SEQ)
.limit(10000)
.fetchArray();
}
public static void insertExecuteLog(ScenarioExecuteLogRecord scenarioExecuteLogRecord){
DSLContext dslContext = JooqRpaSysDBHelper.getDSLContext();
dslContext.insertInto(SCENARIO_EXECUTE_LOG)
.set(SCENARIO_EXECUTE_LOG.LOG_SEQ, scenarioExecuteLogRecord.getLogSeq())
.set(SCENARIO_EXECUTE_LOG.USER_ID, scenarioExecuteLogRecord.getUserId())
.set(SCENARIO_EXECUTE_LOG.EXECUTE_DIV, scenarioExecuteLogRecord.getExecuteDiv())
.execute();
}