pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bad value for type int
2+ messages / 1 participants
[nested] [flat]

* Bad value for type int
@ 2015-08-10 02:08  "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: "Gabriel E. Sánchez Martínez" @ 2015-08-10 02:08 UTC (permalink / raw)
  To: 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



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Bad value for type int
@ 2015-08-10 02:38  "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>
  parent: "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: "Gabriel E. Sánchez Martínez" @ 2015-08-10 02:38 UTC (permalink / raw)
  To: pgsql-jdbc

False alarm!  I made a mistake in a different part of the code, and once 
I fixed it, I am not getting the error anymore.  Apologies for not 
finding this before e-mailing the list, and thanks to everyone for the 
good work!



On 08/09/2015 10:08 PM, "Gabriel E. Sánchez Martínez" wrote:
> 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
>



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2015-08-10 02:38 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10 02:08 Bad value for type int "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>
2015-08-10 02:38 ` "Gabriel E. Sánchez Martínez" <gabrielesanchez@gmail.com>

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