Re: bytea size limit? - Mailing list pgsql-jdbc

From Michael Privat
Subject Re: bytea size limit?
Date
Msg-id 1735399359.20040411214842@ceci.mit.edu
Whole thread Raw
In response to Re: bytea size limit?  (Dave Cramer <pg@fastcrypt.com>)
Responses Re: bytea size limit?  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
Here's the full code sample for a minimalistic reproduction of the
error. When you run it, if you increase the size (through the command
line argument, you get an out of memory error. On my machine, after
the size gets higher than about 1400000 bytes. I can make it happen every
time.

The DB table has two fields:

id: integer
data: bytea


import java.sql.*;
import java.io.*;
import java.util.*;

public class BlobTest {
        public static void main(String[] args) {
                Connection c = null;
                try {
                        Class.forName("org.postgresql.Driver");
                        String url = "jdbc:postgresql://myserver/mydb";
                        c = DriverManager.getConnection(url, "myuser",
                        "mypass");

                        String sql = "INSERT INTO blobtest (id, data)
                        VALUES(?,?)";

                        int size = Integer.parseInt(args[0]);

                        byte[] data = new byte[size];

                        int id = Math.abs(new Random().nextInt());

                        PreparedStatement stmt = c.prepareStatement(sql);
                        stmt.setInt(1, id);
                        stmt.setBinaryStream(2, new ByteArrayInputStream(data), data.length);

                        stmt.executeUpdate();

                        stmt.close();
                }
                catch(Throwable t) {
                        t.printStackTrace();
                }
                finally {
                        try { c.close(); } catch(Exception e) {}
                }
        }
}



Sunday, April 11, 2004, 9:42:16 PM, you wrote:

DC> No, there is no size limit. However you may have better luck with
DC> largeobjects.
DC> Dave
DC> On Sun, 2004-04-11 at 10:57, Michael Privat wrote:
>> Hi. I have Java code that stores binary into the DB. When I use MS SQL
>> Server 2000 (type image) it works fine. But when I use Postgres 7.4 it
>> fails. Is there a size limit setting somewhere I need to set up?
>>
>> Thanks,
>> Michael
>>
>>
>> ---------------------------(end of
>> broadcast)---------------------------
>> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>>


pgsql-jdbc by date:

Previous
From: Dave Cramer
Date:
Subject: Re: bytea size limit?
Next
From: Dave Cramer
Date:
Subject: Re: bytea size limit?