-->
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.  [ 3 posts ] 
Author Message
 Post subject: blob
PostPosted: Thu Mar 11, 2004 10:36 am 
Newbie

Joined: Thu Mar 11, 2004 9:51 am
Posts: 6
Hello I'm using jbuilder X and whatever I do, i can't use nullsafeset bellow the createBlob method won't work:
Code:
public void nullSafeSet(PreparedStatement st, Object value, int index)
  throws HibernateException, SQLException{
    st.setBlob(index, Hibernate.createBlob((byte[]) value));
  }


Thanks and excuse my bad writting since I'm french


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 6:36 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Be more specific

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:57 am 
Newbie

Joined: Thu Mar 11, 2004 9:51 am
Posts: 6
Using this class (found on this web site):

Code:

package 1;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.sql.Blob;
import net.sf.hibernate.Hibernate;
import net.sf.hibernate.UserType;
import net.sf.hibernate.HibernateException;

public class blob implements UserType{

  public int[] sqlTypes(){
    return new int[] { Types.BLOB };
  }

  public Class returnedClass(){
    return byte[].class;
  }

  public boolean equals(Object x, Object y){
    return (x == y)
      || (x != null
        && y != null
        && java.util.Arrays.equals((byte[]) x, (byte[]) y));
  }

  public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
  throws HibernateException, SQLException{
    Blob blob = rs.getBlob(names[0]);
    return blob.getBytes(1, (int) blob.length());
  }

  public void nullSafeSet(PreparedStatement st, Object value, int index)
  throws HibernateException, SQLException{
    st.setBlob(index, Hibernate.createBlob((byte[]) value));
  }
public Blob toBlob(Object f){
  Blob b=null;
  b=Hibernate.createBlob((byte[]) f);
  return b;
}
  public Object deepCopy(Object value){
    if (value == null) return null;
    byte[] bytes = (byte[]) value;
    byte[] result = new byte[bytes.length];
    System.arraycopy(bytes, 0, result, 0, bytes.length);
    return result;
  }

  public boolean isMutable(){
    return true;
  }
}



this code doesn't work

Code:
     JFileChooser fc = new JFileChooser();
     int retour = fc.showOpenDialog(this);
     File a=fc.getSelectedFile();
     Object c=new Object();
     c=(Object) a;
     if (retour == fc.APPROVE_OPTION) {
       nullSafeSet(PrepStmt, c, 1);
     }
   }


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.