Skip site navigation (1) Skip section navigation (2)

Prepared statement parameter and timestamp

From: "ste(dot)buffaishere(at)tin(dot)it" <ste(dot)buffaishere(at)tin(dot)it>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: Prepared statement parameter and timestamp
Date: 2007-04-03 09:28:29
Message-ID: 111b6c6205e.ste.buffaishere@tin.it (view raw or flat)
Thread:
Lists: 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)

Responses

pgsql-jdbc by date

Next:From: Marc MaminDate: 2007-04-05 14:48:41
Subject: Encoding issue (utf8): different strings received from java than from PGAdmin
Previous:From: Oliver JowettDate: 2007-04-03 02:23:19
Subject: Re: psql COPY with JDBC

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group