Quartz调度程序不在dropwizard应用程序中执行SQL查询

Ama*_*man 5 java database sql-server quartz-scheduler dropwizard

我有一个使用dropwizard框架创建的应用程序,我已经注册了一个计划在每个指定的持续时间后运行的quartz-scheduler作业.此作业向SQL Server DB发出SQL查询并迭代ResultSet并将数据设置为POJO类,稍后将其推送到队列.

SQL查询使UNION连接多个表,这些表使用where子句中相关表的last_modified_time列获取在增量时间内修改的记录的数据.pom.xml中包含的DB jar是sqljdbc-4.4.0,quartz版本是2.2.1

查询如下所示:

SELECT 
    u.last_modified_date, 
    u.account_id, 
    u.user_id, 
    ud.is_active 
FROM user u WITH (NOLOCK) 
JOIN user_details ud with (NOLOCK) ON u.account_id = ud.account_id AND u.user_id = ud.user_id 
WHERE u.last_modifed_date > ? AND ud.last_modifed_date <= ?

UNION

SELECT 
    u.last_modified_date, 
    u.account_id, 
    u.user_id, 
    ud.is_active 
FROM user u WITH (NOLOCK) 
JOIN user_details ud with (NOLOCK) ON u.account_id = ud.account_id AND u.user_id = ud.user_id 
JOIN user_registration_details urd WITH (NOLOCK) ON urd.account_id = u.account_id AND urd.user_id = u.user_id AND urd.reg_id = ud.reg_id
WHERE urd.last_modifed_date > ? AND urd.last_modifed_date <= ?
Run Code Online (Sandbox Code Playgroud)

此查询由简单连接语句和结果集调用,如下所示

final ManagedDataSource datasource configuration.getDatabase().build(environment.metrics(), "sql");
// configuration is the configuration class in a drop wizard application and configuration.getDatabase() returns 
// the DataSourceFactory with all credentials like user, password and url set into it
try (Connection conn = dataSource.getConnection()) {
      int resultSetType = SQLServerResultSet.TYPE_SS_SERVER_CURSOR_FORWARD_ONLY;
      int resultSetConcurrency = ResultSet.CONCUR_READ_ONLY;
      LOGGER.info("Starting execution: ");
      try (PreparedStatement pstmt = conn.prepareStatement(getQuery(), resultSetType,resultSetConcurrency))
      {
         setQueryParameters(pstmt);
         try (ResultSet rs = pstmt.executeQuery();) 
         {
           //process results 
         }
     }
  } catch (SQLException | IOException ex) {
        LOGGER.error(“Error occurred “ +  ex);
}
LOGGER.info("Completed execution: ");
Run Code Online (Sandbox Code Playgroud)

在一个简单的执行中,它打印日志"开始执行",然后处理记录并打印"完成执行".但有时在执行期间,它会打印日志"正在执行"和"已完成执行",但此查询实际上并未触发到SQL DB.

由于我没有得到我在该delta时间内修改过的记录,因此我将探查器检查是否实际触发了查询,并且没有发现此查询触发到DB.另外,我尝试添加log4jdbc库http://code.google.com/p/log4jdbc/wiki/FAQ将查询打印到日志中,但没有为此查询打印日志.

Ric*_*mes 2

with (NOLOCK)不是 MySQL 语法。查看向导中的设置,看看您是否指定了正确的 RDBMS 引擎。特别是,它听起来像 SQL Server 语法。

等效的可能涉及将 设为TRANSACTION ISOLATION LEVEL类似 的值READ UNCOMMITTED