Mysql 临时表 是Session 级的
一个方法中若干个jdbcTemplate.execute 未必是唯一连接的
因此关键点在于创建唯一连接的JdbcTemplate
SingleConnectionDataSource scds = null;
try {
scds = new SingleConnectionDataSource(jdbcTemplate.getDataSource().getConnection(), true);
} catch (SQLException e) {
throw new DataAccessResourceFailureException("Unable to create single connnection ds", e);
}
JdbcTemplate scdsJdbcTemplate = new JdbcTemplate(scds);
try{
//操作
}finally{
scds.destroy();
}
参考 http://forum.springsource.org/showthread.php?71548-Spring-JDBC-and-Sybase-Temp-Tables