Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Howto: Put RTF files with Pictures into Blob / Clob

843859Jun 14 2007 — edited Jun 15 2007
Hey gents,

I am having a bit of a problem at the moment. My objective is to store RTF files who, at times, contain pictures into an Oracle 9.2 Database.

So far, I've tried to use CLOBs and BLOBs; and while getting the data into the database doesn't seem to be a problem, I have all the troubles in the world to retrieve the data and put it into a file.

To get the data into the database I use the following code:
                conn.getDBConnection();
                System.out.println(sqlQuery);
                pstmt = conn.dbConnection.prepareStatement(sqlQuery);
                pstmt.setString(1, fileName);
                pstmt.setString(2, absolutePath);
                
                File file = new File(absolutePath);
                InputStream is = (InputStream) new FileInputStream(file);
                pstmt.setBinaryStream(3, is, (int)file.length());
                pstmt.setString(4, "1");
                pstmt.executeUpdate();
and from the quite long hexadecimal values I get when trying to see the result in Aqua Data Studio, it seems to work.

"conn" is the connection;
sqlQuery the query string;
pstmt the PreparedStatement;
fileName and absolutePath are two Strings - storing the file name and the absolute path of the given file.

So far, I've tried to get the data back using:
                conn.getDBConnection();
                pstmt = conn.dbConnection.prepareStatement(sqlQuery);
                rsts = pstmt.executeQuery();
                
                File tmpFile = File.createTempFile("downloaded_", ".rtf");
                
                absolutePathTempFile = tmpFile.getAbsolutePath();
                
                java.io.ObjectOutputStream out = new ObjectOutputStream 
                        (new FileOutputStream(absolutePathTempFile));
                
                if ( rsts.next() ) {
                    out.writeObject(rsts.getClob(1));
                }
So far to no avail; and - as I want to hastily add - without really understanding what was happening - as I failed to find a tutorial, how to or any hints I could use to put to good use.

Is there somebody who got an idea on what to do, so that I'd be able to sucessfully "upload" and "download" a RTF file (with some pictures) into a Oracle 9.2 (if that makes any difference) database?

Any help would be greatly appreciated

Bob
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 13 2007
Added on Jun 14 2007
3 comments
650 views