我无法使 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 com.simba.athena.athena.jdbc42.AJJDBC42ObjectFactory.createPreparedStatement(Unknown Source)
at com.simba.athena.jdbc.common.SConnection.prepareStatement(Unknown Source)
at com.simba.athena.jdbc.common.SConnection.prepareStatement(Unknown Source)
at ****************************************************
Caused by: com.simba.athena.support.exceptions.GeneralException: [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
... 37 more
难道我做错了什么 ?这是代码
@Test
public void testWhichFails() throws SQLException {
try (Connection connection = athenaConnexion()) {
String sql = "select * from my_table where col = ? limit 10";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
ps.setInt(1, 30);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
System.out.println("rs.getString(1) = " + rs.getString(1));
}
}
}
}
}
@Test
public void testWhichWorks() throws SQLException {
try (Connection connection = athenaConnexion()) {
String sql = "select * from my_table where col = 30 limit 10";
try (PreparedStatement ps = connection.prepareStatement(sql)) {
//ps.setInt(1, 30);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
System.out.println("rs.getString(1) = " + rs.getString(1));
}
}
}
}
}
Athena 仅支持此处列出的 SQL 函数Athena SQL 函数反过来又基于函数和运算符 Presto 版本 0.172与以下列表Athena 的 SQL 相关限制。新版Presto中可以使用Prepared statements急速文档。不过,Athena 尚不支持这个新版本。您可以随时写信给 Athena 支持团队,要求添加 PREPARE 功能。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)