ORA-00903: niepoprawna nazwa tabeli w PreparedStatement
Mam metodę, która wykona zapytanie z listą QueryParameters dla przygotowanej instrukcji. TheHelperConnection
iQueryParameter
są po prostu małymi ziarnami java i powinny być zrozumiałe na podstawieget
widzisz tutaj. Próbuję zrobićselect * from dual
używając, zamiast aselect * from ?
gdzieQueryParameter
jest typu STRING, a wartość todual
. Jednak dostajęjava.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
błąd. Mój kod i dane wyjściowe są poniżej. Co tam?
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;
}
Wydajność:
The connection is: //.....My connection
The query is: select * from ?
The QueryParameters are:
String - dual