BLOB/Large objects - Mailing list pgsql-jdbc

From Max Larsson
Subject BLOB/Large objects
Date
Msg-id 002801c14fd6$0d9d8ff0$0c64140a@gmservice.de
Whole thread Raw
List pgsql-jdbc
Hi,

i have a problem with reading large object with the JDBC driver. I am using
Postgresql
in conjunction with Cocoon2 just so you know where the code fragement is
comming
from. I adopted the example from the Postgresql documention, but the
following problem
is apaering. The variable contentlength is always zero. This the while loop,
which
reads the file and supplies it as response is not entered. Why?? But i what
i tested
and worked was to extract the file on the server with lo_export function in
sql. So
why does it not work with JDBC?

best regards

Max


        ....
        try {
            datasource = (DataSourceComponent) dbselector.select(dsn);
            con = datasource.getConnection();

            con.setAutoCommit(false);

            PreparedStatement statement = con.prepareStatement("SELECT file
FROM files WHERE name = ?");
            statement.setString(1, this.source);
            ResultSet set = statement.executeQuery();

            if( set.next() ) {
              getLogger().debug( "Helpdesk :
PostgresqlDatabaseReader/serialize : result set = " + set );
              InputStream is = new
BufferedInputStream(set.getBinaryStream(1));

              long expires =
parameters.getParameterAsInteger("expires", -1);

              if (expires > 0) {
                  response.setDateHeader("Expires", new Date().getTime() +
expires);
              }

              response.setHeader("Accept-Ranges", "bytes");

              byte[] buffer = new byte[8192];
              int length = -1;

              while ((length = is.read(buffer)) > -1) {
                  getLogger().warn( "read " + length + " bytes" );
                  out.write( buffer, 0, length);
                  contentlength += length;
              }
              is.close();
              out.flush();

            }
            else
              throw new ResourceNotFoundException("There is no image with
that key");

            set.close();
            statement.close();

            con.commit();
        } catch (Exception e) {
            getLogger().warn("Could not get resource from Database", e);

            con.rollback();

            throw new ResourceNotFoundException("DatabaseReader error:", e);
        }

        getLogger().warn( "Contentlength is " + contentlength );
        ....


pgsql-jdbc by date:

Previous
From: "Arsalan Zaidi"
Date:
Subject: Re: [INTERFACES] java.lang.OutOfMemory Exception with a large number of inserts
Next
From: Mark "Lillywhite (pg-jdbc)"
Date:
Subject: J2SE 1.4 and other patches