Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZOcyo-0002Yk-D2 for pgsql-jdbc@arkaria.postgresql.org; Mon, 10 Aug 2015 02:38:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZOcyn-0001Zz-UT for pgsql-jdbc@arkaria.postgresql.org; Mon, 10 Aug 2015 02:38:25 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZOcym-0001Zl-2C for pgsql-jdbc@postgresql.org; Mon, 10 Aug 2015 02:38:24 +0000 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZOcyf-00037U-NO for pgsql-jdbc@postgresql.org; Mon, 10 Aug 2015 02:38:22 +0000 Received: by qgj62 with SMTP id 62so84172323qgj.2 for ; Sun, 09 Aug 2015 19:38:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=fir+wFNtHiz5tJT6MJjs9mRAvAoGZHuI9qNPRBLR2cs=; b=D8xK1T8ijjJgVjm3nyThXTwVUbvGIuTP6nz4543l33A+yjYnNaFcPFRdvbfs4sosNb +zeRQiTcKvNr345WuKDf4azED41ZVEejyBMUuDRB1P4NtFhHyaJ+iN9EMd4QFbENjkSo MRMD3WHdWDr51nlEfPIBRNFF+IfJS6WalZYumvGkZaAEhI6q4bZebaA1Hfx0CjIujWg6 RQSEzh6l5prlwQLNf/U99k44TodMZwrIZFna+zSFauAPtR2PTRsrkTLcfTlprog+Jh4v QH5YViiXsIaN6/T9XtniEwCndURaCm76nkse/PPB0EE/aQ+noumKh4RJalSUkJ+9Cqv9 P2CQ== X-Received: by 10.140.201.200 with SMTP id w191mr35986580qha.50.1439174296670; Sun, 09 Aug 2015 19:38:16 -0700 (PDT) Received: from [18.189.11.37] (dhcp-18-189-11-37.dyn.MIT.EDU. [18.189.11.37]) by smtp.googlemail.com with ESMTPSA id g2sm4657873qgg.22.2015.08.09.19.38.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Aug 2015 19:38:16 -0700 (PDT) Message-ID: <55C80E97.5030407@gmail.com> Date: Sun, 09 Aug 2015 22:38:15 -0400 From: =?UTF-8?B?IkdhYnJpZWwgRS4gU8OhbmNoZXogTWFydMOtbmV6Ig==?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.8.0 MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: Bad value for type int References: <55C80783.70703@gmail.com> In-Reply-To: <55C80783.70703@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org 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