【问题标题】:Spring JDBCTemplate with Temporary Table带有临时表的 Spring JDBCTemplate
【发布时间】:2015-10-06 09:07:19
【问题描述】:

我有几个问题:

1) 第一个基本问题如何执行多个语句 (创建临时表并从临时表中选择)在spring jdbctemplate中使用相同的jdbc连接?

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

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

【问题讨论】:

    标签: java mysql spring


    【解决方案1】:

    在 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));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-05
      • 2017-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 2013-04-21
      • 2013-07-23
      相关资源
      最近更新 更多