problem with storing BLOBs larger then 2MB - Mailing list pgsql-jdbc

From Michal Josifek
Subject problem with storing BLOBs larger then 2MB
Date
Msg-id 001401c1b491$11db5910$0e1ea8c0@mike
Whole thread Raw
Responses Re: problem with storing BLOBs larger then 2MB
Re: problem with storing BLOBs larger then 2MB
List 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
(2132 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();


   }

}



pgsql-jdbc by date:

Previous
From: john-paul delaney
Date:
Subject: NewB: Servlet/cmd:Classpath confusion
Next
From: "Nick Fankhauser"
Date:
Subject: Re: NewB: Servlet/cmd:Classpath confusion