Thanks, Jose
finally, i use jdbc directly since i want to have as less dependency as possible, but obviously the limition is it tightly couple with postgresql driver classes
| | | // Get the Large Object Manager to perform operations with |
| | | LargeObjectManager lobj = ((org.postgresql.PGConnection) conn).getLargeObjectAPI(); |
| | | stmt = conn.prepareStatement("SELECT content FROM content WHERE id = ?"); |
| | | stmt.setLong(1, contentId); |
| | | ResultSet rs = stmt.executeQuery(); |
| | | if (rs != null) { |
| | | | if (rs.next()) { |
| | | | | // Open the large object for reading |
| | | | | long oid = rs.getLong(1); |
| | | | | LargeObject obj = lobj.open(oid, LargeObjectManager.READ); |
| | | | | // Read the data |
| | | | | byte buf[] = new byte[obj.size()]; |
| | | | | obj.read(buf, 0, obj.size()); |
| | | | | // Do something with the data read here |
| | | | | // Close the object |
| | | | | obj.close(); |
| | | | | return buf; |
| | | | } |
| | | | rs.close(); |
| | | } |
| | | conn.commit(); |
| | } |
| | catch (Exception e) { |
| | | e.printStackTrace(); |
| | } |
| | finally { |
| | | try { |
| | | | if (conn != null) |
| | | | | conn.close(); |
| | | | if (stmt != null) |
| | | | | stmt.close(); |
| | | } |
| | | catch (SQLException e) { |
| | | | e.printStackTrace(); |
| | | } |
| | } |
| | return null; |
| } |