我有一个方法,它将使用准备好的语句的 QueryParameters 列表执行查询。HelperConnection
and只是小型 java bean,根据您在此处看到QueryParameter
的 s 应该是不言自明的。get
我正在尝试select * from dual
使用,而不是使用select * from ?
STRINGQueryParameter
类型且值为dual
. 但是,我遇到了一个java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
错误。我的代码和输出如下。这是怎么回事?
public static ResultSet executeQuery(HelperConnection helperConnection, String query, QueryParameter... params) throws SQLException {
System.out.println("The connection is: " + helperConnection.getJdbcURL());
System.out.println("The query is: " + query);
if (params.length > 0) {
System.out.println("The QueryParameters are:");
System.out.println("\t" + StringHelper.splitBy(StringHelper.newline + "\t", params));
}
Connection conn = helperConnection.createOracleConnection();
PreparedStatement pstmt = conn.prepareStatement(query);
for (int i = 1; i <= params.length; i++) {
QueryParameter param = params[i - 1];
switch (param.getType()) {
//Other cases here
case QueryParameter.STRING:
pstmt.setString(i, param.getValue());
break;
}
}
ResultSet rs = pstmt.executeQuery();
conn.commit();
return rs;
}
输出:
The connection is: //.....My connection
The query is: select * from ?
The QueryParameters are:
String - dual