準備されたステートメントの QueryParameters のリストを使用してクエリを実行するメソッドがあります。HelperConnection
とは単なる小さな Java Bean であり、ここに表示QueryParameter
されている に基づいて一目瞭然get
です。select * from dual
代わりに、が STRING 型で値が である usingselect * from ?
をQueryParameter
実行しようとしています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