From: Roland Walter <rwa@mosaic-ag.com>
To: Papp Márton <papp.marton@assixo.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: timestamp parameter is null
Date: Wed, 01 Feb 2006 17:51:25 +0100
Message-ID: <43E0E70D.9000701@mosaic-ag.com> (raw)
In-Reply-To: <43E0DFE1.9020200@assixo.com>
References: <43E0DFE1.9020200@assixo.com>
Papp Márton schrieb:
> Hello List!
>
> I have the following problem:
>
> I'm trying to execute a simple SQL query with JDBC and I get an
> exception, which I don't understand why. Here's the code:
>
> public static void main(String[] args) throws Exception {
> Class.forName("org.postgresql.Driver");
> Connection conn =
> DriverManager.getConnection("jdbc:postgresql://localhost:5434/dbname",
> "user", "pass");
> PreparedStatement stm = conn.prepareStatement("select * from
> tablename where ? is not null");
> stm.setTimestamp(1, new Timestamp(new Date().getTime()));
> stm.executeQuery();
> }
>
> The exception is:
>
> Exception in thread "main" org.postgresql.util.PSQLException: ERROR:
> could not determine data type of parameter $1
> at
> org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1512)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1297)
>
> at
> org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:430)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:346)
>
> at
> org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:250)
>
> at Test6.main(Test6.java:15)
>
> The server version is 8.1.0. The Jdbc driver is
> postgresql-8.1-404.jdbc3.jar.
>
> The same code runs fine with the 7.4 jdbc driver. It's also okay, if
> I'm using any other type than timestamp. Actually, I tried "string"
> and it worked.
>
You cannot set a table or column name with a prepared statement with the
protocol in the version 3.
This might only work if you set the protocol to version 2 in the
connection url:
"jdbc:postgresql://localhost:5434/dbname?protocolVersion=2"
But this may have disadvantages, as for example the index search for
columns with BIGINT values
will not work with a standard sql-statement. You would have to write
something like:
SELECT * FROM table WHERE column=(? CAST BIGINT);
--
Roland Walter mailto: rwa (at) mosaic-ag (dot) com
MOSAIC SOFTWARE AG phone: +49 (0) 22 25 / 88 2-44 9
Am Pannacker 3 fax: +49 (0) 22 25 / 88 2-20 1
D-53340 Meckenheim http://www.mosaic-ag.com
Die in dieser E-Mail enthaltenen Nachrichten und Anhaenge sind ausschliesslich
fuer den bezeichneten Adressaten bestimmt. Sie koennen rechtlich geschuetzte,
vertrauliche Informationen enthalten. Falls Sie nicht der bezeichnete Empfaenger
oder zum Empfang dieser E-Mail nicht berechtigt sind, ist die Verwendung,
Vervielfaeltigung oder Weitergabe von Nachrichten und Anhaengen untersagt.
Falls Sie diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte
unverzueglich den Absender und vernichten Sie die E-Mail.
This e-mail message and any attachment are intended exclusively for the named
addressee. They may contain confidential information which may also be protected
by professional secrecy. Unless you are the named addressee (or authorised to
receive for the addressee) you may not copy or use this message or any attachment
or disclose the contents to anyone else. If this e-mail was sent to you by mistake
please notify the sender immediately and delete this e-mail.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: rwa@mosaic-ag.com, papp.marton@assixo.com
Subject: Re: timestamp parameter is null
In-Reply-To: <43E0E70D.9000701@mosaic-ag.com>
References: <43E0DFE1.9020200@assixo.com> <43E0E70D.9000701@mosaic-ag.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox