Solved

Blob type update

Posted on 2002-03-04
4
308 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Microsoft is moving in-place eDiscovery & hold from ECP to EOP console under Content Search in Search and Investigation Options.  In this post, I will be showing you how to export emails to a PST file using the Content Search Options.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

707 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