- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个 executorservice 来调用下面列出的具有不同日期范围的查询。当我同步运行它时,我没有看到任何错误。但是,当我并行启动多个线程来调用 getTransactionResult 时,我看到
java.util.concurrent.ExecutionException: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [Query]; ORA-01841: (full) year must be between -4713 and +9999, and not be 0 ; nested exception is java.sql.SQLDataException: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
at java.util.concurrent.FutureTask.report(FutureTask.java:122) at java.util.concurrent.FutureTask.get(FutureTask.java:192) at com.cloud.cloudreport.CloudReportApplication.lambda$1(CloudReportApplication.java:94) at java.util.ArrayList.forEach(ArrayList.java:1249) at com.cloud.cloudreport.CloudReportApplication.run(CloudReportApplication.java:92) at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:776) at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:760) at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:747) at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) at com.cloud.cloudreport.CloudReportApplication.main(CloudReportApplication.java:43) Caused by: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; ORA-01841: (full) year must be between -4713 and +9999, and not be 0 ; nested exception is java.sql.SQLDataException: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:82) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:649) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:711) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:761) at org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate.queryForObject(NamedParameterJdbcTemplate.java:211) at com.cloud.cloudreport.dao.TransactionRespository.getTransactionResult(TransactionRespository.java:68) at com.cloud.cloudreport.dao.TransactionRespository$$FastClassBySpringCGLIB$$60dee75d.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:721) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:656) at com.cloud.cloudreport.dao.TransactionRespository$$EnhancerBySpringCGLIB$$ca18ee4e.getTransactionResult() at com.cloud.cloudreport.CloudReportApplication.lambda$0(CloudReportApplication.java:76) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.sql.SQLDataException: ORA-01841: (full) year must be between -4713 and +9999, and not be 0
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:58) at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:776) at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:897) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1034) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3820) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3867) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1502) at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:692) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633) ... 18 more
为了并行执行该方法,我需要对此进行任何更改吗?
@Repository
public class TransactionRespository {
private static Logger LOG = LoggerFactory.getLogger(TransactionRespository.class);
@Autowired
private NamedParameterJdbcTemplate jdbcTemplate;
private String transactionQuery = " query goes here";
public TransactionDetails getTransactionResult(String serviceName, String operationName, Date startDate,
Date endDate) {
SqlParameterSource namedParameters = new MapSqlParameterSource("serviceName", serviceName)
.addValue("operationName", operationName)
.addValue("startDate", new DateTime(startDate).toString("yyyy-MM-dd HH:mm:ss"))
.addValue("endDate", new DateTime(endDate).toString("yyyy-MM-dd HH:mm:ss"));
try{
return (TransactionDetails) this.jdbcTemplate.queryForObject(transactionQuery, namedParameters,(rs,rowNum)->{
TransactionDetails transactionDetails = new TransactionDetails();
TransactionResult result = new TransactionResult();
transactionDetails.setStartDate(new DateTime(startDate).toString("yyyy-MM-dd HH:mm:ss"));
transactionDetails.setEndDate(new DateTime(endDate).toString("yyyy-MM-dd HH:mm:ss"));
result.setSuccessfulTransactions(rs.getInt(2));
result.setFailedTransactions(rs.getInt(3));
Map<String,TransactionResult> operationResult = new TreeMap<>();
operationResult.put(operationName, result);
transactionDetails.setOperationResult(operationResult);
return transactionDetails;
});
} catch (EmptyResultDataAccessException e) {
LOG.debug("start date :: {} , end date :: {} " , new DateTime(startDate).toString("yyyy-MM-dd HH:mm:ss"), new DateTime(endDate).toString("yyyy-MM-dd HH:mm:ss"));
return null;
}
}
最佳答案
getTransactionResult(...) 没有任何同步。容器可以管理东西,但保持秩序取决于你。容器无法知道什么需要同步。
您可以使该方法同步或遵循此
关于java - Spring JDBCTemplate - 并发调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42677895/
应用程序上下文中的一些bean的依赖关系形成一个循环:当我使用时@Autowired私有(private) JdbcTemplate jdbcTemplate;不同类(class) 错误提示: ***
我做一个查询: jdbcTemplate.query(sqlQueryForGetNodes, new Object[]{treeId, versionId}, rs -> { NodeTy
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 3 年前。 Improve this ques
根据 Spring documentation ,Spring JdbcTemplate的使用步骤如下:
我做了这个简单的应用程序来连接到 MySQL 数据库,我收到了这个错误: org.springframework.jdbc.core.JdbcTemplate 在我的配置中 (com.kubamadr
我遵循了SpringBoot框架中的示例,该框架从这里开始,当我尝试添加Spring Bean时得到下一个错误。Pom.xml。我尝试插入到BD中,BD没有改变,应用程序本身可以工作,但没有连接数据库
我遵循了SpringBoot框架中的示例,该框架从这里开始,当我尝试添加Spring Bean时得到下一个错误。Pom.xml。我尝试插入到BD中,BD没有改变,应用程序本身可以工作,但没有连接数据库
我正在学习 Spring Boot 和 jdbcTemplate 的组合以进行一些基本的 crud 操作,并试图更好地理解我应该选择哪种更新方法。 我理解以下两种类方法(改编自 this post)将
如何使用行映射器向表中插入数据? 我正在尝试: Employee user1 = jtemplate.queryForObject("INSERT INTO employee(id, name,sal
我最近切换到 Spring Framework 而不是手动处理 JDBC,这主要是一个很好的过渡。但是,一个程序开始出现奇怪的问题:如果数据库速度很慢,则在调用 getJdbcTemplate().u
命令(Command)模式是指将请求封装成为一个对象,使发出请求和执行请求的责任分割开,方便将命令对象进行存储、传递、调用、增加与管理。 也就是将发送者、接收者和调用命令封装成独立的对象,来供客户端调
我有一个 spring 应用程序,它的主页会触发多个 ajax 调用,这些调用又从数据库中获取数据并返回。数据库已配置连接池,minPoolSize 为 50,maxPoolSize 为 100。 现
有人可以指出我以下 Spring Jdbc 模板代码中的任何错误吗? 当我点击删除时,记录没有被删除,也没有显示错误。 public void delete(String id) { logg
我正在使用 spring JDBCTemplate。 我有一个场景,其中需要传递到查询函数中的参数是条件/可选的。例如,我有以下代码: List result = jdbcTemplate.query
在项目中我在Hibernate和Spring jdbctemplate中是混合使用的。我添加了乐观锁定。 Hibernate 非常适合版本控制,但现在我必须转换所有这些 jdbctemplate 代码
我已经为我的INSERT查询建立了一个DAO。码: DAO public class EmployeeDao { JdbcTemplate template; public void
我有一个sql查询。 String sql = "SELECT ? FROM Users WHERE Lastname=?"; 我使用 JDBCTemplate 中的 queryForList 方法
我正在尝试将嵌套查询与 JdbcTemplate 一起使用,但发现了问题,在我看来,它不支持嵌套查询..我是对的吗?或者我需要改变什么? 所以,我调用 getJdbcTemplate().query
这个问题是几年前提出的,但答案对我来说不起作用。我已将建议的注释添加到配置和 dao 中。我确信模板实际上正在连接到数据库,因为当我的列太小时,我收到了适当的错误。更新调用正在执行单行插入,并且毫无异
JdbcTemplate 对象和 SimpleJdbcTemplate 之间有什么区别? 最佳答案 截至Spring 3.1 SimpleJdbcTemplate已弃用,SimpleJdbcTempl
我是一名优秀的程序员,十分优秀!