public inbox for [email protected]
help / color / mirror / Atom feedSubject: [Pljava-dev] How to read LargeObject with pljava?
Date: Sat, 13 Jun 2009 12:43:17 +0300
Message-ID: <[email protected]> (raw)
Hi everybody!
Have some code to read LargeObject from db and create digest message for
the it content. The code generate an error attemtting to read a portion
of LO.
Could anybody give an example how to read LO from database?
I'm using jre1.6.0.13, pljava1.4.0, postgresql8.3.7.
Thanks.
import java.io.FileOutputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Logger;
import org.postgresql.largeobject.LargeObject;
import org.postgresql.largeobject.LargeObjectManager;
public class ServerDigestCreator {
public static String
anotherCreateStrDigest(org.postgresql.pljava.internal.Oid lObjectId)
throws SQLException,NoSuchAlgorithmException
{
String digest = null;
java.sql.Savepoint sp = null;
if(lObjectId==null) return null;
java.sql.Connection aConnection =
DriverManager.getConnection("jdbc:default:connection");
try{
sp = aConnection.setSavepoint();
org.postgresql.pljava.internal.LargeObject lo =
org.postgresql.pljava.internal.LargeObject.open(lObjectId,
org.postgresql.pljava.internal.LargeObject.INV_READ);
MessageDigest aDigest = MessageDigest.getInstance("md5");
if(lo==null) {
aConnection.releaseSavepoint(sp);
return digest;
}
byte buf[] = new byte[2048];
int s=0;
while((s = lo.read(buf))!=0)
<---------------------- Error occurs here
=============================================================
aDigest.update(buf); byte[] digestByteArray
= aDigest.digest();
BigInteger tempBI = new BigInteger(digestByteArray);
digest = tempBI.toString(); lo.close();
aConnection.releaseSavepoint(sp);
}
catch(SQLException ex)
{ if(sp!=null)
aConnection.rollback(sp);
Logger.getAnonymousLogger().info("ERROR: " + ex.getMessage()
+ "\n");
throw new SQLException(ex.getMessage());
}
return digest;
}
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Subject: Re: [Pljava-dev] How to read LargeObject with pljava?
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox