我有一个spring应用程序,它的功能之一是能够获取任何SQL片段并运行它,轮询器轮询文件夹中包含SQL文件位置的触发文件,然后该应用程序读取SQL文件,然后将内容放入“ sqlquery”消息标题中。
我们似乎遇到的问题是,当SQL失败时不会引发异常。
try
{
if ((msg.getHeaders().containsKey("sqlQuery"))&&(!"".equals(msg.getHeaders().get("sqlQuery"))))
{
_log.debug("Executing: " + msg.getHeaders().get("sqlQuery"), UID);
jdbcTemplate.execute((String) msg.getHeaders().get("sqlQuery"));
_log.info("Query executed successfully.", UID);
}
result = "S";
} catch (Exception ex) {
ex.printStackTrace();
_log.error(ex, ex, UID);
}
JDBC驱动程序是Microsoft JDBC驱动程序4.2,可连接到SQL Server 2014数据库。
我尝试使用简单的“选择1/0”运行它,这显然会引发被零除的错误,但是我们获得了成功的响应。
2018-07-19 16:36:01,738|org.springframework.jdbc.datasource.DataSourceUtils|sqlFileChannelTaskExecutor-6|DEBUG|Returning JDBC Connection to DataSource
2018-07-19 16:36:01,738|org.springframework.integration.transformer.MessageTransformingHandler|sqlFileChannelTaskExecutor-6|DEBUG|org.springframework.integration.transformer.MessageTransformingHandler@c6d1b7 received message: GenericMessage [payload={UPDATED=1}, headers={UID=MCTest, errorChannel=logSqlErrorChannel, id=318f54b8-2889-22af-1009-e191550c75eb, sqlQuery=Select 1/0, timestamp=1532014561738}]
2018-07-19 16:36:01,738|org.springframework.beans.factory.support.DefaultListableBeanFactory|sqlFileChannelTaskExecutor-6|DEBUG|Returning cached instance of singleton bean 'integrationEvaluationContext'
2018-07-19 16:36:01,738|org.springframework.beans.factory.support.DefaultListableBeanFactory|sqlFileChannelTaskExecutor-6|DEBUG|Returning cached instance of singleton bean 'integrationConversionService'
2018-07-19 16:36:01,738|MCTest|sqlFileChannelTaskExecutor-6|DEBUG|SQL Step Started
2018-07-19 16:37:16,926|MCTest|sqlFileChannelTaskExecutor-6|DEBUG|Executing: Select 1/0
2018-07-19 16:37:22,530|org.springframework.jdbc.core.JdbcTemplate|sqlFileChannelTaskExecutor-6|DEBUG|Executing SQL statement [Select 1/0]
2018-07-19 16:37:28,278|org.springframework.jdbc.datasource.DataSourceUtils|sqlFileChannelTaskExecutor-6|DEBUG|Fetching JDBC Connection from DataSource
2018-07-19 16:37:28,278|org.springframework.jdbc.datasource.DriverManagerDataSource|sqlFileChannelTaskExecutor-6|DEBUG|Creating new JDBC DriverManager Connection to [jdbc:sqlserver://<Server>;databaseName=<Database]
2018-07-19 16:37:33,069|org.springframework.jdbc.datasource.DataSourceUtils|sqlFileChannelTaskExecutor-6|DEBUG|Returning JDBC Connection to DataSource
2018-07-19 16:37:33,069|MCTest|sqlFileChannelTaskExecutor-6|INFO |Query executed successfully.
谁能帮助解释为什么未捕获/抛出异常?
答案 0 :(得分:0)
分享您的查询..,并使用catch (ArithmeticException ae)
,好像您在理解1/0 ArithmeticException时遇到问题。
希望它能工作。