使用临时表的Spring JDBCTemplate

3

我有几个问题:

1)首先是一个基本问题:如何使用同一JDBC连接在Spring JdbcTemplate中执行多个语句(创建临时表和从临时表选择)?

2)我正在使用以下SQL语句创建临时表。但是,JDBCTemplate的execute(String sql)方法不接受任何参数,那么该如何使用JDBC模板运行它呢?

Select column1, column2, column3... into #t 
from Table where column1 >= ? and column1 < ?
1个回答

0
在JUtil中,我使用单个连接包装器:
dataSource = new org.springframework.jdbc.datasource.SingleConnectionDataSource(dataSource.getConnection(), true);

@Test
public void testTemporaryTable() {
    JdbcTemplate dao = new JdbcTemplate(dataSource);
    dao.update("create local temporary table test_table as select 'text' id");
    Assert.assertEquals("text", dao.queryForObject("select id from test_table ", String.class));
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接