problem with storing BLOBs larger then 2MB

From: "Michal Josifek" <michal(dot)josifek(at)shoppinggate(dot)cz>
To: <pgsql-jdbc(at)postgresql(dot)org>
Subject: problem with storing BLOBs larger then 2MB
Date: 2002-02-13 13:19:29
Message-ID: 001401c1b491$11db5910$0e1ea8c0@mike
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Hello,
I have this problem. I need to store some files into my DB and there is (I mean) a problem with last (from jdbc.postgresql.org) stable jdbc driver (stable driver for pgsql 7.2, java2). When I try to store file larger than 2MB (2 132 220), exception

java.lang.OutOfMemoryError
<<no stack trace available>>
Exception in thread "main"

occured on line "executeUpdate()".

Thanks for help

Michal Josifek

Client computer:
JDBC driver: last stable from jdbc.postgresql.org
OS: w2k
JDK: Sun 1.3.1_01

Server computer:
DB: stable 7.2
OS: Linux RH 7.2

Table SQL:

CREATE TABLE "files" (
"id" int4 DEFAULT nextval('"files_id_seq"'::text) NOT NULL,
"name" varchar(250),
"size" int4,
"file" bytea,
"note" varchar(50),
CONSTRAINT "files_pkey" PRIMARY KEY ("id")
) WITHOUT OIDS;

Sample code:

/*
* db_test.java
*
*/

package tests;

/**
*
* @author Michal
* @version
*/

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

public class db_test {
private Connection conn;

/** Creates new db_test */
public db_test() {
}


public void writeFile(String strFileName,String strNote) throws java.lang.Exception {

File fil = new File(strFileName);
FileInputStream fis = new FileInputStream(fil);
System.out.println(fil.length());
PreparedStatement ps;

ps = this.conn.prepareStatement("insert into files (name,size,file,note) values(?, ?, ?, ?)");
ps.setString(1,fil.getName());
ps.setInt(2,(int)fil.length());
ps.setBinaryStream(3,fis,(int)fil.length());
ps.setString(4,strNote);

ps.executeUpdate(); // EXCEPTION LINE !!!!!
ps.close();
fis.close();
this.conn.commit();
}

/**
* @param args the command line arguments
*/
public static void main (String args[]) throws java.lang.Exception {
Class.forName("org.postgresql.Driver");

db_test dbts = new db_test();

dbts.conn = DriverManager.getConnection("jdbc:postgresql://192.168.30.190:5432/postgres","user","pass");
dbts.conn.setAutoCommit(false);

dbts.writeFile("d:/java/openssl.tar.gz","Note");

dbts.conn.close();


}

}

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Nick Fankhauser 2002-02-13 14:01:21 Re: NewB: Servlet/cmd:Classpath confusion
Previous Message john-paul delaney 2002-02-13 11:55:59 NewB: Servlet/cmd:Classpath confusion