How to resolve the "Tried to send an out-of-range integer as a 2-byte value" error

See original GitHub issue

I’m submitting a question about “Tried to send an out-of-range integer as a 2-byte value”

  • [ jdbc driver] bug report
  • feature request

Introduce

Jdbc execute a long/batch insert sql,  like: ```insert into values(?,?,?),(?,?,?),(?,?,?)...```
but client throws an error: "Tried to send an out-of-range integer as a 2-byte value:" ... 
When I review the source code, and I find the implementation like below:

Background

Maven pom.xml

<dependency>
     <groupId>org.postgresql</groupId>
     <artifactId>postgresql</artifactId>
     <version>42.2.5</version>
</dependency>

Source Code

 [Line: 1442]  QueryExecutorImpl.java

  // ....
   pgStream.sendInteger2(params.getParameterCount());

 // ....

[Line: 235] PGStream.java

// ....
public void sendInteger2(int val) throws IOException {
    if (val < Short.MIN_VALUE || val > Short.MAX_VALUE) {
      throw new IOException("Tried to send an out-of-range integer as a 2-byte value: " + val);
    }

    _int2buf[0] = (byte) (val >>> 8);
    _int2buf[1] = (byte) val;
    pg_output.write(_int2buf);
  }
....

Describe the issue A clear and concise description of what the issue is.

I don't know why param count should be greater/equals than Short.MIN_VALUE (-32768) 
or less/equals than Short.MAX_VALUE (32767). 
When I execute batch sql (especially build lots of columns ), 
this error must be occurred. I can not guess the check whether  to protect the server side?  
I think the jdbc driver client should not limit the length of statement. 
We can use MAX_ALLOWED_PACKET parameter which is defined in MySQL server in the server side.
Wait for your response asap !!!

Java Version

java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

OS Version

Mac OSX

PostgreSQL Version

EnterpriseDB 9.3.17.42 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55), 64-bit

To Reproduce Steps to reproduce the behaviour:

Expected behaviour A clear and concise description of what you expected to happen. And what actually happens

Logs If possible PostgreSQL logs surrounding the occurrence of the issue Additionally logs from the driver can be obtained adding

loggerLevel=TRACE&loggerFile=pgjdbc-trace.log 

to the connection string

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:31 (20 by maintainers)

github_iconTop GitHub Comments

21reactions
vlsicommented, Oct 17, 2018

So what can I do ?

Did you know that what can I do sounds very close to Russian водка найду (English pronunciation is вот кан ай ду) which means I'll find Vodka ?

1reaction
vlsicommented, Jun 14, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

Tried to send an out-of-range integer as a 2-byte value
Currently I got exception when collection is very large: java.io.IOException: Tried to send an out-of-range integer as a 2-byte value I heard ...
Read more >
Java.io.IOException:Tried to send a out-of-range integer as a ...
Problem: When the JDBC driver for PG prepared statement parameter set, a sending size on the client side is limited to 2-byte. Workaround:...
Read more >
Error "Tried to send an out-of-range integer as a 2-byte value
Resolution. Option 1. Remove unused groups. Option 2. Unlock the project permission. Cause. This is due to the ...
Read more >
Tried to send an out-of-range integer as a 2-byte value
Issue Summary. When trying to export analytics data for a large space (100k) pages, we will hit into "java.io.IOException: Tried to send an...
Read more >
[Solved]-PostgreSQL and Hibernate java.io.IOException
Coding example for the question PostgreSQL and Hibernate java.io.IOException: Tried to send an out-of-range integer as a 2-byte value-Hibernate.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found