Solved

Blob type update

Posted on 2002-03-04
4
307 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
[X]
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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying 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

Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

730 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