我无法让 AWS Athena JDBC 驱动程序使用 PreparedStatement 和绑定变量。如果我将列的所需值直接放在 SQL 字符串中,它就可以工作。但是如果我使用占位符 '?' 我用 PreparedStatement 的 setter 绑定变量,它不起作用。当然,我们知道我们必须使用第二种方式(用于缓存,避免 SQL 注入等)。
我使用 JDBC 驱动程序 AthenaJDBC42_2.0.2.jar。尝试使用占位符 '?' 时出现以下错误 在 SQL 字符串中。当我从 JDBC 连接获取 PreparedStatement 时抛出错误。它抱怨找不到参数。但是我在代码中设置了它们。如何在获取 PreparedStatement 之前设置参数 :-) ?
java.sql.SQLException: [Simba][AthenaJDBC](100071) An error has been thrown from the AWS Athena client. SYNTAX_ERROR: line 1:1: Incorrect number of parameters: expected 1 but found 0
at com.simba.athena.athena.api.AJClient.executeQuery(Unknown Source)
at com.simba.athena.athena.dataengine.AJQueryExecutor.<init>(Unknown Source)
at com.simba.athena.athena.dataengine.AJDataEngine.prepare(Unknown Source)
at com.simba.athena.jdbc.common.SPreparedStatement.<init>(Unknown Source)
at com.simba.athena.jdbc.jdbc41.S41PreparedStatement.<init>(Unknown Source)
at com.simba.athena.jdbc.jdbc42.S42PreparedStatement.<init>(Unknown Source)
at com.simba.athena.jdbc.jdbc42.JDBC42ObjectFactory.createPreparedStatement(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) 在AWS Athena中,似乎没有将参数传递到SQL查询的好方法.执行的典型方式是boto3 来电,
response = client.start_query_execution(
QueryString='string',
ClientRequestToken='string',
QueryExecutionContext={
'Database': 'string'
},
ResultConfiguration={
'OutputLocation': 'string',
'EncryptionConfiguration': {
'EncryptionOption': 'SSE_S3'|'SSE_KMS'|'CSE_KMS',
'KmsKey': 'string'
}
}
)
Run Code Online (Sandbox Code Playgroud)
如果我需要将参数传递给QueryString,我需要清理它以避免注入攻击.如何清洁输入?