db-ojb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carlos Henrique Leclerc De Oliveira <clecl...@uolinc.com>
Subject RE: OJB + Oracle BLOB
Date Fri, 03 Oct 2003 13:53:24 GMT
Hi Ohara,
 
I have one...
 
I will send to list ok...
 
In this example, I am using only PersistenceBrokerFactoryIF to get
connection and then I use pure JDBC to store and retrieve BLOB 
fields. This solution can store more than 4k using oracle thin driver for
8i. The oracle thin driver have a bug when store more than 4k. 
This is the exemple code I used...
 
The queries:
 
    public static final String loadBlobForUpdate =
            "SELECT BLB_ATTRIBUTE FROM TABLE_A " +
            "WHERE KEY=? FOR UPDATE";
 
    public static final String updateSession =
            "UPDATE TABLE_A SET " +
            "BLB_ATTRIBUTE=?, " +
            "WHERE KEY=?";
 
    public static final String insertSession =
            "INSERT INTO TABLE_A " +
            "(KEY, BLB_ATTRIBUTE) " +
            "VALUES (?,empty_blob())";
 
To create BLOB object:
 
    private BLOB createBlob(Connection con)
    throws SQLException
    {
        PreparedStatement ps = null;
        PreparedStatement ps2 = null;
        ResultSet rs = null;
        BLOB blob = null;
 
            con.setAutoCommit(false);
            if(!persisted)
            {
                ps = con.prepareStatement(insertSession);
                ps.setString(1, this.id);
                ps.executeUpdate();
                ps.close();
            }
 
            ps2 = con.prepareStatement(loadBlobForUpdate);
            ps2.setString(1, this.id);
            rs = ps2.executeQuery();
 
            if(rs.next())
            {
                blob = ((OracleResultSet)rs).getBLOB(1);
            }
            else
            {
                throw new SQLException("Could not load blob field");
            }
 
        return blob;
  }
 
 
To store BLOB, code:
 
        PreparedStatement ps = null;
            BLOB blob = createBlob(con, sessionType, secondsToExpire);
            blob.putBytes(1, baAttributes);
            ps =
con.prepareStatement(DBPersistentSessionQueries.updateSession);
            ps.setBlob(1, blob);
            ps.setInt(2, secondsToExpire);
            ps.setString(3, this.id);
            con.commit();

To read BLOB, and deserialize objects....Use ObjectInputStream 
to read objects from stream.
 
        PreparedStatement ps = null;
        ResultSet rs = null;
            ps =
con.prepareStatement(DBPersistentSessionQueries.loadSession);
            ps.setString(1, this.id);
            rs = ps.executeQuery();
            // Read blob field and deserialize attributes
                InputStream is = rs.getBinaryStream(1);
                deserializeAttributes(is);
                is.close();

regards,
Carlos Henrique
 
-----Original Message-----
From: OharaSu@via.com.tw [mailto:OharaSu@via.com.tw]
Sent: sexta-feira, 3 de outubro de 2003 06:12
To: cleclerc@uolinc.com
Subject: OJB + Oracle BLOB



Hi
 
 
Did you have any solution about OJB + Oracle + BLOB
Would you send me a example if you have one ?
 
 
 
sincerely
 
 
 
ohara
 
 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message