• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inserting BLOB in Oracle with Studio 4..

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,
I am receiving a strange error in WebSphere studio 4. I want to insert a file into Oracle 8i database in a BLOB column. Here is the code..
public void storeFile()
{

int pk_file = getNewPK();
String filename = "F:\\FaultTolerence.pdf";
Connection connection = null;
PreparedStatement pstmt = null;
Statement stmt = null;
try {
connection = pool.getConnection();
connection.setAutoCommit(false);
pstmt = connection.prepareStatement("INSERT INTO file_master( pk_file,file,filename) VALUES(? ,EMPTY_BLOB(),'FaultTolerence.pdf')");
pstmt.setInt(1, pk_file);
pstmt.execute();
System.out.println("Created.\n Loading into Blob column ...");
stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT attachment,filename FROM file_master WHERE pk_file = "+pk_file+" FOR UPDATE");

if( rs.next() ) {
Blob attachment = rs.getBlob(1);
OutputStream blobOutputStream = ((oracle.sql.BLOB)attachment).getBinaryOutputStream();
File file = new File(filename);
InputStream sampleFileStream = new FileInputStream(file);
byte[] buffer = new byte[10* 1024];
int nread = 0; // Number of bytes read
while((nread= sampleFileStream.read(buffer)) != -1) // Read from file
blobOutputStream.write(buffer, 0, nread); // Write to Blob

sampleFileStream.close();
blobOutputStream.close();
connection.commit();
System.out.println("\nSize of stored file "+file.length());
} // END OF ID
} catch( Exception ex ) { System.out.println("\n" + ex.toString());}
finally {try { pstmt.close(); stmt.close(); } catch(SQLException ex) { } }
}
The same code works ABSOLUTELY FINE in JBuilder. But in WebSphere studio I receive Exception saying
oracle/jdbc/driver/OracleResultSet.getBlob: java.lang.AbstractMethodError: oracle/jdbc/driver/OracleResultSet.getBlob

The exception is thrown at
Blob attachment = rs.getBlob(1); statement.
I tried numerous variations. But in vain.
Any help is most welcome.
Thanks a lot
Regards,
Bhiku Mhatre
[ August 07, 2003: Message edited by: Bhiku Mhatre ]
[ August 07, 2003: Message edited by: Bhiku Mhatre ]
 
Bhiku Mhatre
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is continuation of my previous post.
The code to insert BLOB into Oracle also works perfectly in WAS 4.01 advanced edition. that promptm me to speculate if this is a bug in WSAD.
May be Kyle can enlighten.
Thanks a lot,
Regards,
Bhiku.
 
Bhiku Mhatre
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is continuation of my previous post.
The code to insert BLOB into Oracle also works perfectly in WAS 4.01 advanced edition. That forces me to speculate if this is a bug in WSAD.
May be, Kyle can enlighten.
Thanks a lot,
Regards,
Bhiku.
reply
    Bookmark Topic Watch Topic
  • New Topic