Prepared statement parameter and timestamp - Mailing list pgsql-jdbc

From ste.buffaishere@tin.it
Subject Prepared statement parameter and timestamp
Date
Msg-id 111b6c6205e.ste.buffaishere@tin.it
Whole thread Raw
Responses Re: Prepared statement parameter and timestamp
List pgsql-jdbc
Why this code:

PreparedStatement ps = conn.prepareStatement(

"SELECT date_trunc('week', {ts ?})");
ps.setTimestamp(1, new java.sql.
Timestamp(
                new java.util.Date().getTime()));
ResultSet rs = ps.
executeQuery();
while(rs.next()) {
    debug(rs.getString(1));
}

fails miserably with
org.postgresql.util.PSQLException: ERROR: syntax
error at or near "$1"
        at org.postgresql.core.v3.
QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1531)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults
(QueryExecutorImpl.java:1313)
        at org.postgresql.core.v3.
QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
        at org.
postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.
java:452)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.
executeWithFlags(AbstractJdbc2Statement.java:354)
        at org.
postgresql.jdbc2.AbstractJdbc2Statement.executeQuery
(AbstractJdbc2Statement.java:258)

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: psql COPY with JDBC
Next
From: "Marc Mamin"
Date:
Subject: Encoding issue (utf8): different strings received from java than from PGAdmin