Prepared statement problem
Prepared statement problem
От:
Djordje Nikolic <djordje@abanka.co.yu>
Дата:
I had a problem with PreparedStatement which uses ? after FROM clause.
Server reported org.postgresql.util.PSQLException: ERROR: syntax error
at or near "$1"
This is simplified example.
PreparedStatement pstmt;
try {
pstmt = conn.prepareStatement("SELECT * FROM ?");
pstmt.setString(1, "ps_nalog");
pstmt.executeQuery();
} catch (SQLException ex) {
ex.printStackTrace();
}
Can anybody tell me where is posibble to put ? in a SELECT statement !
best regards,
Djordje Nikolic
www.abanka.co.yu
Re: Prepared statement problem
От:
Dave Cramer <pg@fastcrypt.com>
Дата:
jdbc is using server side prepared statements.
As such the server won't allow this particular construct.
You can put the ? in for where something = ?
Dave
On 25-Apr-07, at 7:30 AM, Djordje Nikolic wrote:
> I had a problem with PreparedStatement which uses ? after FROM clause.
> Server reported org.postgresql.util.PSQLException: ERROR: syntax
> error at or near "$1"
>
> This is simplified example.
>
> PreparedStatement pstmt;
> try {
> pstmt = conn.prepareStatement("SELECT * FROM ?");
> pstmt.setString(1, "ps_nalog");
> pstmt.executeQuery();
> } catch (SQLException ex) {
> ex.printStackTrace();
> }
>
> Can anybody tell me where is posibble to put ? in a SELECT statement !
>
> best regards,
> Djordje Nikolic
>
> www.abanka.co.yu
>
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster