Uma ideia mais eficiente,
olha como funciona XML, e encodeia em xml, salva o arquivo gerado no banco em formato texto, ao recuperar o texto é só mandar ler o arquivo e tá ok obj recuperado.
 
[]´s
----- Original Message -----
Sent: Thursday, August 15, 2002 9:21 AM
Subject: [java-list] Como gravar um objeto no banco postgresql - Oque está errado ?

Olá Pessoal,
 
Preciso da ajuda de vocês : Como faço para gravar um objeto no banco postgresql ?
Que tipo de campo de usar no banco ?
Algum código que me ajude ?
 
Estou fazendo da seguinte maneira :
usei o campo tipo bytea e oid no postgresql.
 
  public static void setValue(String key, Object obj) {
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(baos);
      out.writeObject(obj);
      baos.flush();
      byte bytes[] = baos.toByteArray();
      baos.close();
      String sql = "INSERT INTO dados VALUES(? ,?)";
      BDSistema bd = new BDSistema();
      PreparedStatement stmt = bd.getConnection().prepareStatement(sql);
      stmt.setString(1,key);
      stmt.setBytes(2,bytes);
      stmt.executeUpdate();
      bd.soltaConexao();
    } catch (Exception e) {
      System.out.println("erro :" + e.getMessage());
      e.printStackTrace();
    }
  }
Ocorre este erro :
 
FastPath call returned ERROR:  lo_write: invalid large obj descriptor (0)
 at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:141)
 at org.postgresql.fastpath.Fastpath.fastpath(Fastpath.java:191)
 at org.postgresql.largeobject.LargeObject.write(LargeObject.java:173)
 at org.postgresql.jdbc2.PreparedStatement.setBytes(PreparedStatement.java:300)
 at SOE.setValue(SOE.java:98)
 at SOE.main(SOE.java:123)
erro :FastPath call returned ERROR:  lo_write: invalid large obj descriptor (0)

Responder a