【发布时间】:2021-11-12 10:36:42
【问题描述】:
当使用带有参数化 PreparedStatement 的 QUERY_BAND 时,我得到了这个异常:
java.sql.SQLException: [Teradata Database] [TeraJDBC 16.20.00.04] [Error 5992] [SQLState HY000] A syntax error was found in the QUERY_BAND.
我的代码:
String queryBand = "SET QUERY_BAND = ? UPDATE FOR SESSION VOLATILE;";
try {
dbConnection = baseJDBCTemplate.getDataSource().getConnection();
//set user name in the Query Band
try (PreparedStatement stmt = dbConnection.prepareStatement(queryBand)) {
stmt.setString(1, "USER=x256;");//"+rtId+"
stmt.execute(queryBand);
}
catch (SQLException e) {
throw new SIRRestitGeneratorException("DB Exception ",e);
}
我做了同样的事情推荐 n Teradata 文档 https://docs.teradata.com/r/eWpPpcMoLGQcZEoyt5AjEg/RH2BOZYzHp6u4dhsrWbRlw
我正在使用 Teradata 版本 16.20.00.04 Spring Boot 1.5.8
【问题讨论】:
-
不要...只需使用
JdbcTemplate您已经必须执行代码。您的代码存在缺陷,因为它泄漏了连接。只需执行jdbcTemplate.update即可执行查询。 -
感谢您的回复,但我在执行行之前尝试 (PreparedStatement stmt = dbConnection.prepareStatement(queryBand)) { 在此行中遇到异常
-
不管你仍然应该使用 jdbcTemplate 而不是你现在使用它的方式。执行
baseJdbcTemplate.update(queryBand, "USER=x256");之类的操作。不多不少,抛弃一切。 -
我遇到了同样的问题 [Teradata Database] [TeraJDBC 16.20.00.04] [错误 5992] [SQLState HY000] 在 QUERY_BAND 中发现语法错误。
-
UPDATE FOR SESSION VOLATILE有效吗?
标签: java spring teradata jdbctemplate