-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [hibernate][oracle 10g]enregistrer blob
PostPosted: Mon Apr 25, 2005 12:28 pm 
Newbie

Joined: Fri Apr 15, 2005 4:57 am
Posts: 13
Location: Lyon, France
Bonjour,

how to simply record an image in a field blob oracle?

I created my fields : image BLOB DEFAULT EMPTY_BLOB()

Which type to use in my file of mapping (BLOB oracle, Blob sql, Blob hibernate) ?

I found many examples on Internet but none went.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 8:47 am 
Newbie

Joined: Fri Apr 15, 2005 4:57 am
Posts: 13
Location: Lyon, France
I have a SibImage object which contains the URL of my image. My datamodel contains an attribute: SibImage image;
I thus create a hibernate type to parse my address of image in BLOB (oracle). Here is my SibImageBlobType class (only the méthoe Set interests us):

Code:
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
      // pas d'image
      st.setNull(index, Types.BLOB);
      return;
    }

    InputStream inStream = null;
    try {

      // création d'une connexion vers l'image
      URLConnection urlCnx = ((SibImage) value).getImageUrl().openConnection();

      //récupération du flux
      inStream = urlCnx.getInputStream();

      //    lecture du flux et écriture dans un tableau de bytes
      ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(1024);
      for (int val; (val = inStream.read()) != -1;) {
        byteArrayStream.write(val);
      }
      st.setBlob(index, BLOB.empty_lob());
}


This code is right so I add this:

Code:
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
      // pas d'image
      st.setNull(index, Types.BLOB);
      return;
    }

    InputStream inStream = null;
    try {

      // création d'une connexion vers l'image
      URLConnection urlCnx = ((SibImage) value).getImageUrl().openConnection();

      //récupération du flux
      inStream = urlCnx.getInputStream();

      //    lecture du flux et écriture dans un tableau de bytes
      ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(1024);
      for (int val; (val = inStream.read()) != -1;) {
        byteArrayStream.write(val);
      }
            Connection conn = st.getConnection().getMetaData().getConnection();

      BLOB blob = BLOB.createTemporary(conn, false, oracle.sql.BLOB.DURATION_SESSION);

      blob.open(BLOB.MODE_READWRITE);

      OutputStream out = blob.getBinaryOutputStream();

      try {
        out.write(byteArrayStream.toByteArray());
        out.flush();
        out.close();
      }
      catch (IOException e) {
        throw new SQLException("failed write to blob" + e.getMessage());
      }

      blob.close();

      ((oracle.jdbc.OraclePreparedStatement) (st)).setBLOB(index, blob);
}


I obtain this error :

Code:
Caused by: java.lang.NoSuchMethodError: oracle.sql.BLOB.createTemporary(Ljava/sql/Connection;ZI)Loracle/sql/BLOB;
   at fr.ggl.fwk.service.hibernate.types.SibImageBlobType.nullSafeSet(SibImageBlobType.java:119)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 8:47 am 
Newbie

Joined: Fri Apr 15, 2005 4:57 am
Posts: 13
Location: Lyon, France
Hello,

I have a SibImage object which contains the URL of my image. My datamodel contains an attribute: SibImage image;
I thus create a hibernate type to parse my address of image in BLOB (oracle). Here is my SibImageBlobType class (only the méthoe Set interests us):

Code:
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
      // pas d'image
      st.setNull(index, Types.BLOB);
      return;
    }

    InputStream inStream = null;
    try {

      // création d'une connexion vers l'image
      URLConnection urlCnx = ((SibImage) value).getImageUrl().openConnection();

      //récupération du flux
      inStream = urlCnx.getInputStream();

      //    lecture du flux et écriture dans un tableau de bytes
      ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(1024);
      for (int val; (val = inStream.read()) != -1;) {
        byteArrayStream.write(val);
      }
      st.setBlob(index, BLOB.empty_lob());
}


This code is right so I add this:

Code:
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
    if (value == null) {
      // pas d'image
      st.setNull(index, Types.BLOB);
      return;
    }

    InputStream inStream = null;
    try {

      // création d'une connexion vers l'image
      URLConnection urlCnx = ((SibImage) value).getImageUrl().openConnection();

      //récupération du flux
      inStream = urlCnx.getInputStream();

      //    lecture du flux et écriture dans un tableau de bytes
      ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(1024);
      for (int val; (val = inStream.read()) != -1;) {
        byteArrayStream.write(val);
      }
            Connection conn = st.getConnection().getMetaData().getConnection();

      BLOB blob = BLOB.createTemporary(conn, false, oracle.sql.BLOB.DURATION_SESSION);

      blob.open(BLOB.MODE_READWRITE);

      OutputStream out = blob.getBinaryOutputStream();

      try {
        out.write(byteArrayStream.toByteArray());
        out.flush();
        out.close();
      }
      catch (IOException e) {
        throw new SQLException("failed write to blob" + e.getMessage());
      }

      blob.close();

      ((oracle.jdbc.OraclePreparedStatement) (st)).setBLOB(index, blob);
}


I obtain this error :

Code:
Caused by: java.lang.NoSuchMethodError: oracle.sql.BLOB.createTemporary(Ljava/sql/Connection;ZI)Loracle/sql/BLOB;
   at fr.ggl.fwk.service.hibernate.types.SibImageBlobType.nullSafeSet(SibImageBlobType.java:119)


thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 9:13 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Assuming this compiled, it looks like the version of the Oracle JDBC driver you're running against is different than the one you're compiling against, and doesn't contain the method indicated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.