Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Blob type update

Posted on 2002-03-04
4
306 Views
Last Modified: 2010-04-01
I don't understand why.... I can't seems to update blob field type. Is there a special type of update for blob type? I will get the value from the form, typecast it to string then update the db. All fields can be updated except the blob type field....
0
Comment
Question by:yan_er04
4 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 6841748
how are you trying to update it?

Are you inserting it back as binary?

if you have it as a string update it passing stringvarname.getBytes() as the value.

CJ
0
 
LVL 6

Accepted Solution

by:
kotan earned 30 total points
ID: 6849440
Here is the example of insert BLOB object into oracle db

public void insertFile(Connection conn ,int idocId, byte[] bydata1) {
  try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection("jdbc:oracle:thin:@XXXserver:1521:database", "scott", "tiger");

    conn.setAutoCommit(false);
    stmt = conn.createStatement();
    stmt.execute("INSERT into " + SDocData +" values ('"              + idocId + "', EMPTY_BLOB()) ");
    rs = stmt.executeQuery("select * from "+ SDocData + "where doc_id = '" + idocId + "' for update of file_data");

    while(rs.next()) {
      blob = (oracle.sql.BLOB)rs.getObject(2);
    }

    System.out.println(" Blob length before insert " + blob.length());
    java.io.OutputStream os = ((oracle.sql.BLOB)blob).getBinaryOutputStream();

    os.write(bydata1);
    os.flush();
    os.close();

    System.out.println("Blob length in the database " + blob.length());
    OraclePreparedStatement ops =(OraclePreparedStatement)conn.prepareStatement ("update Doc_Data set file_data=? where  " +" doc_id = '" + idocId + "'");
    ops.setBLOB(1, blob);
    ops.execute();
  } catch (IOException e) {
    e.printStackTrace();
  }
}
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9552545
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

"Accept kotan's comment as answer."
 
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Kuldeepchaturvedi
EE Cleanup Volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IT certifications are a concrete representation of continual learning on the part of the candidate.  Continual learning is necessary for the long term success of an IT professional, but are IT certifications the right path for you?
There's a lot of hype surrounding blockchain technology. Here's how it works and some of the novel ways it' s now being used - including for data protection.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question