Issue
When using QUERY_BAND whith paramitrized PreparedStatement, i got this exception :
java.sql.SQLException: [Teradata Database] [TeraJDBC 16.20.00.04] [Error 5992] [SQLState HY000] A syntax error was found in the QUERY_BAND.
My code :
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);
}
i did the same thing recomanded n Teradata documentation https://docs.teradata.com/r/eWpPpcMoLGQcZEoyt5AjEg/RH2BOZYzHp6u4dhsrWbRlw
i'm using Teradata version 16.20.00.04 Spring Boot 1.5.8
Solution
Finally i found the response in this doc https://docs.teradata.com/r/rgAb27O_xRmMVc_aQq2VGw/oXcSulxgPuaDnG0qMLYYrg
The ? parameter is not supported for SESSION, it's supported only for TRANSACTION.
String queryBand = "SET QUERY_BAND=? UPDATE FOR SESSION VOLATILE;"; // not accepted
String queryBand = "SET QUERY_BAND=? UPDATE FOR TRANSACTION;"; // accepetd
So in my case (updating the session), i can't use the ? parameter, so i use this (even i have sonar security alert):
String queryBand = "SET QUERY_BAND='USER="+StringEscapeUtils.escapeSql(rtfeId)+";' UPDATE FOR SESSION VOLATILE;";
Answered By - ⵔⴰⴼⵉⵇ ⴱⵓⵖⴰⵏⵉ