Passagem de um BLOB via Entity Bean

1 resposta
chun

Gostaria de saber como fazer para passar um BLOB ( um arquivo… ) via EntityBean…

saka meu codigo…

public class DigBeanClient {

  public static void main( String [] args )
  {
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
          env.put(Context.PROVIDER_URL, "localhost:1099");
          env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
          try
          {
                  Context ctx = new InitialContext(env);
                  Object obj = ctx.lookup( "DigBean" );
                  DigHome home =
                  (DigHome)javax.rmi.PortableRemoteObject.narrow(obj, DigHome.class);
                  java.sql.Date data = new java.sql.Date(new java.util.Date().getTime());
                  java.sql.Time hora = new java.sql.Time(new java.util.Date().getTime());
                  java.io.FileInputStream arquivo = new java.io.FileInputStream("/imagens/1_002f.tif");
                  arquivo.read();
                  DigRemote Dig = home.create(new Integer(1),new Integer(1),"Descricao 1","TIF",(Object)arquivo,data,hora,new Integer(1),data,hora,new Integer(1));
                  System.out.println("Foi...");
          }
          catch ( Exception e )
          {
                  e.printStackTrace();
                  System.out.println( "Exception: " + e.getMessage() );
          }
  }
}

Soh tah dando dau de “NotSerializableException” , na hora de passar o fileInputStream… ok… se ele nao pode ser passado … o que eh que pode ? quero mandar essa imagem para meu entity bean mas tah dificil :confused:

1 Resposta

chun

well… descobri como…

vc tem que serializar um array de bytes caso queira passar algo como um arquivo ou um objeto em forma de arquivo…

File imgFile = new File("/imagens/1_002f.tif");
                  long imgFileSize= imgFile.length();
                  byte[] byteValue = new byte[(int)imgFileSize];
                  InputStream is = new BufferedInputStream(new  FileInputStream(imgFile));
                  int len = is.read(byteValue);

ae eh soh passar o byteValue de parametro para seu entity bean :wink:

Criado 25 de novembro de 2004
Ultima resposta 26 de nov. de 2004
Respostas 1
Participantes 1