How to read blob data from HSQL Database


#1

Hi

Just wondering if anyone can help me to query the database and convert blob data into a readable format.

  1. I wrote a simple Java application to connect to database

conn = DriverManager.getConnection(“jdbc:hsqldb:”+db_file_name,“username”,“password”);

  1. I then created a select query on EXG_EXCHANGE table
    db.query(“SELECT DETAIL FROM PUBLIC.EXG_EXCHANGE”);

  2. I tried converting to a string and printed out and I tried calling getBlob method but all I get back is ascii code.

My last attempt was the following code:

blob = rs.getBlob(“DETAIL”);

blobInputStream=blob.getBinaryStream();
in = new BufferedReader(new InputStreamReader(blobInputStream));
while ((str=in.readLine()) !=null) {
fullBlobText +=str;
}
System.out.println(fullBlobText);


#2

I am taking a guess here. Is the blob data stored in database fields a Joda object?


#3

Or is it a Fudge Message and how do I extract the blob and convert the fudge message to readable content?


#4

Well, the answers are all in DbExchangeMaster which is the class we’d recommend you use to read the database. Not sure why you’re not using the existing tested class?

(The source code will tell you that it stores Fudge binary data, and there are specific helper classes for reading/writing the blob, but as the approach varies by database, it is abstracted)


#5

Where can I find the helper classes for reading/writing the blob? Do you have any basic tutorials/examples that can assist my learning curve?


#6

The blob is written using:
byte[] bytes = FUDGE_CONTEXT.toByteArray(env.getMessage());
new SqlLobValue(bytes, getDialect().getLobHandler()), Types.BLOB)
where the dialect is an instance of DbDialect.

The blob is read using:
byte[] bytes = lob.getBlobAsBytes(rs, “DETAIL”);
ManageableExchange exchange = FUDGE_CONTEXT.readObject(ManageableExchange.class, new ByteArrayInputStream(bytes));