Solved

Blob type update

Posted on 2002-03-04
4
302 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now