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!

Transferring a BLOB from java to Oracle

Mohammed SardarNov 18 2014 — edited Nov 20 2014

Hi All,

I'm trying to transfer a pdf file from Java to Oracle to store into a table which has a data type of BLOB.

so, In order to transfer I have converted the data

to byte array so that it will be passed as BLOB. I debug and debug through Netbeans not getting any clue to resolve my error.

The error message is ERROR          : java.sql.SQLException: ORA-06502: PL/SQL: numeric or value error: character to number conversion error

ORA-06512: at line 1.  The data type that will be mapped is BLOB data type.

I have confirmed with other items that passed to the oracle procedure any they are fine with their data types.. Why becuase

only I try transfer a file getting this error if not then I'm not getting any error.

Could some one give some ideas how can I go on from here ?

Thanks

if (hasImage(block.getData(DOC_FILENAME_FD))) {

                      try {

                          File file1 = new File(block.getData(DOC_FILENAME_FD));

                          InputStream inputStream = new FileInputStream(file1);

                          //byte[] docBlob = null;

                         docBlob = readFully(inputStream);

                      }

                      catch(FileNotFoundException e){                                          

                      }

                      catch(IOException e1){                                          

                      }

                     

Funciton to read the PDF and convert to byte array.

public byte[] readFully(InputStream stream) throws IOException {

        byte[] buffer = new byte[1024];

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        int bytesRead;

        while ((bytesRead = stream.read(buffer)) != -1)        {

            baos.write(buffer, 0, bytesRead);

        }

        return baos.toByteArray();

    }

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2014
Added on Nov 18 2014
3 comments
2,550 views