我一直试图用预先准备好的语句从我的机器导出到Athena DB。查询给定
"INSERT INTO "default"."bjhfhj" VALUES ('?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?')"代码:
preparedStatement= dbConnection.prepareStatement(insertQuery.toString());
preparedStatement.setString(1, "<colValue>");对于这段代码,我得到了错误"[Simba][JDBC](10940) Invalid parameter index: 1."
堆栈跟踪:
com.simba.athena.exceptions.ExceptionConverter.toSQLException(Unknown Source)
com.simba.athena.jdbc.common.SPreparedStatement.checkValidParameterIndex(Unknown Source)
com.simba.athena.jdbc.common.SPreparedStatement.setString(Unknown Source)精确的java代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class AmazonAthena {
public static void main(String[] args) {
String connection_URL = "jdbc:awsathena://athena.<AWSREGION>.amazonaws.com:443;User=<ACCESS_KEY>;Password=<SECRET_KEY>;S3OutputLocation=<S3_OUTPUT_LOCATION>;";
Connection connection = null;
try {
Class.forName("com.simba.athena.jdbc.Driver");
connection = DriverManager.getConnection(connection_URL);
PreparedStatement preparedStatement= connection.prepareStatement("INSERT INTO \"dataprepdb\".\"bjhfhj\" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
String value = "dhv";
for (int i=0;i<20;i++){
preparedStatement.setString(i+1,value+i);
}
preparedStatement.executeUpdate();
} catch (SQLException | ClassNotFoundException e) {
System.out.printf("error");
throw new RuntimeException(e);
}
}
}我怎么才能解决这个问题?
发布于 2022-11-03 06:27:08
您的SQL错误。那个?是占位符,不要用‘’包裹。
这是正确的:
"INSERT INTO default.bjhfhj VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"您应该知道如何为preparedStatement使用占位符。
====
试试这个:
“插入t_user (id)值(?)"
query.setParameter(0,someVarId);
如果不管用,我也帮不了你。对不起。
https://stackoverflow.com/questions/74298635
复制相似问题