From: | "Gabriel E(dot) Sánchez Martínez" <gabrielesanchez(at)gmail(dot)com> |
---|---|
To: | pgsql-jdbc(at)postgresql(dot)org |
Subject: | Bad value for type int |
Date: | 2015-08-10 02:08:03 |
Message-ID: | 55C80783.70703@gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Hello everyone,
Is there a known bug that makes the postgres JDBC driver treat long
variables as int variables, in the context of prepared statements?
I am getting the following error:
org.postgresql.util.PSQLException: Bad value for type int : 2759496100
while executing a prepared statement with the following Java code:
StringBuilder sb = new StringBuilder();
sb.append("SELECT * FROM table ");
sb.append("WHERE timestamp BETWEEN ? AND ? ");
sb.append("AND id IN ( ");
for (int i = 0; i < ids.size() - 1; i++) {
sb.append("?, ");
}
sb.append("? );");
final String query = sb.toString();
try (Connection c = db.getConnection()) {
PreparedStatement p = c.prepareStatement(query);
p.setDate(1, new java.sql.Date(startDate.getTime()));
p.setDate(2, new java.sql.Date(endDate.getTime()));
for (int i = 0; i < ids.size(); i++) {
int arg = 3 + i;
long id = ids.get(i);
p.setLong(arg, id);
}
ResultSet r = p.executeQuery();
This code is being executed by tomcat7 on Ubuntu 14.04, and I am using
the current version of the driver, 9.4-1201. The query executes well on
pgAdmin in all cases, and in tomcat7 only when all the long ids are in
the int range.
Help will be greatly appreciated!
Regards,
Gabriel
From | Date | Subject | |
---|---|---|---|
Next Message | Gabriel E. Sánchez Martínez | 2015-08-10 02:38:15 | Re: Bad value for type int |
Previous Message | Prasanth Reddy | 2015-08-09 18:44:51 | Re: Fwd: Re: Re: Postgresql 9.4.4 - ERROR: invalid byte sequence for encoding "UTF8": 0x92 |