Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem in inserting BLOB data type intp Oracle DB

  Asked By: Darcy    Date: Dec 16    Category: Java    Views: 4278

I have some problem when I want to insert BLOB data type to oracle DB
I get the exception following:

java.lang.AbstractMethodError: oracle.jdbc.driver.OracleResultSetImpl.getBlob(Ljava/lang/String;)Ljava/sql/Blob;

at line that I write
Blob blob = resultset.getBlob(1);
oracle.sql.BLOB blob = (oracle.sql.BLOB)resultset.getBlob("sample");
when I write each of these 2 lines I get the above exception.

I have used empty_blob() function in this program

I copied my source code here:

public void create() {
BufferedInputStream in = null;
OutputStream out = null;

try {
// insert a row into the BLOB table, use the empty_blob() construct for
// the BLOB field. empty_blob() creates the BLOB locator for Oracle
statement = getStatement(false);
statement.executeUpdate("INSERT INTO tracksamples (recordingid, tracknumber," +
" sample) VALUES (1, 1, empty_blob())");
// Retrieve the row that was just inserted
resultset = statement.executeQuery("SELECT sample FROM tracksamples WHERE " +
"recordingid = 1 AND tracknumber = 1 for update");
if (resultset.next()) {
// Get the BLOB locator
oracle.sql.BLOB blob = (oracle.sql.BLOB)resultset.getBlob("sample");
// Get the output stream which will be used to send data to the table.
// Use Oracle extension because JDBC 2.0 does not support writing data to BLOB
//out = ((oracle.sql.BLOB) blob).getBinaryOutputStream();
out = blob.getBinaryOutputStream();
// Let driver compute buffer size for writing to BLOB
//int bufferSize = (int) ((oracle.sql.BLOB) blob).getBufferSize();
int bufferSize = (int) blob.getBufferSize();
// Create a buffered stream to read from the file
in = new BufferedInputStream(new FileInputStream(sampleFile), bufferSize);
// Create a byte buffer and start reading from the file
byte[] b = new byte[bufferSize];
int count = in.read(b, 0, bufferSize);
// write the bytes using the OutputStream
// loop until all bytes are written to the table
System.out.print("Storing data in database.");
while (count != -1) {
out.write(b, 0, count);
count = in.read(b, 0, bufferSize);
// Close the Input and Output Streams
// The Output stream MUST be closed before the commit
out = null;
in = null;
//And finally, commit the changes



No Answers Found. Be the First, To Post Answer.

Didn't find what you were looking for? Find more on Problem in inserting BLOB data type intp Oracle DB Or get search suggestion and latest updates.