From: | "Max Larsson" <max(dot)larsson(at)gmservice(dot)de> |
---|---|
To: | "'Postgres JDBC'" <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | BLOB/Large objects |
Date: | 2001-10-08 08:48:49 |
Message-ID: | 002801c14fd6$0d9d8ff0$0c64140a@gmservice.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 );
....
From | Date | Subject | |
---|---|---|---|
Next Message | Arsalan Zaidi | 2001-10-08 10:03:11 | Re: java.lang.OutOfMemory Exception with a large number of inserts |
Previous Message | Barry Lind | 2001-10-08 06:39:51 | Re: flames! |