- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要根据他们提取的数据为各种查询范围设置查询超时。即,每个查询都有自己的超时时间。
比如说,查询 A - > 10 MINUTES
查询 B - > 5 分钟
现在如何使用 getJDBCTemplate() 设置这些不同的时间。当我尝试下面的代码片段时,超时被覆盖,无论设置如何,两个查询都在同一时间超时!
Thread t1 = new Thread(new Runnable() {
public void run() {
getJdbcTemplate().setQueryTimeout(5);
List t = getJdbcTemplate()
.query("select top 10000 * from ABC",new RowMapper<T>(){
..
});
Thread t2 = new Thread(new Runnable() {
public void run() {
getJdbcTemplate().setQueryTimeout(10);
List t = getJdbcTemplate()
.query("select top 30000 * from XYZ",new RowMapper<T>() {
..
});
t1.start();
t2.start();
<bean id="dSource" class="com.xyz.DSource" >
<property name="dataSource" ref="dataSource"/>
</bean>
public abstract class AbstractData {
private DSource dSource;
public JdbcTemplate getJdbcTemplate(){
ApplicationContext Ctx = ContextUtils.getApplicationContext();
dSource = (DSource)Ctx.getBean("dSource");
return dSource.getJDBCTemplate();
}
}
public class DSource extends JdbcDaoSupport{
public JdbcTemplate getJdbcTemplate(){
return getJdbcTemplate();
}
}
public Class Dao extends AbstractData{
public void callQuery(){
[AS already posted, t1 and t2 are 2 threads for 2 diff methods/queries using
getJDBCTemplate Of abstract classs]
Thread 1
Thread 2
}
}
最佳答案
超时被覆盖可能是因为您的 JdbcTemplate 是单例的(请添加其配置)。为了实现你想要的,你需要为每个类(或方法)专用的 JdbcTemplate 。
Thread t1 = new Thread(new Runnable() {
public void run() {
JdbcTemplate template = new JdbcTemplate(dataSource);
template.setQueryTimeout(5);
List t = template
.query("select top 10000 * from ABC",new RowMapper<T>(){
..
});
Connection con = jdbcTemplate.getDataSource().getConnection()
preparedstatement = con.prepareStatement(sql);
preparedstatement.setQueryTimeout(theTimeout);
关于spring - JDBCTemplate setQueryTimeout 特定于每个查询,即查询级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20889062/
应用程序上下文中的一些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
我是一名优秀的程序员,十分优秀!