RE: Save java objects using JDBC - Mailing list pgsql-interfaces
From | Peter Mount |
---|---|
Subject | RE: Save java objects using JDBC |
Date | |
Msg-id | 1B3D5E532D18D311861A00600865478CF1B436@exchange1.nt.maidstone.gov.uk Whole thread Raw |
In response to | Save java objects using JDBC (Rob Judd <rjudd@mlug.missouri.edu>) |
Responses |
RE: Save java objects using JDBC
|
List | pgsql-interfaces |
No, when you forget to setAutoCommit(false) you get a different exception. This is a protocol error. What version of both the Backend, JDBC Driver and JDK are you using? Peter -- Peter Mount Enterprise Support Officer, Maidstone Borough Council Email: petermount@maidstone.gov.uk WWW: http://www.maidstone.gov.uk All views expressed within this email are not the views of Maidstone Borough Council -----Original Message----- From: Rob Judd [mailto:rjudd@mlug.missouri.edu] Sent: Tuesday, October 17, 2000 2:57 AM To: pgsql-interfaces@postgreSQL.org Subject: [INTERFACES] Save java objects using JDBC I'm sorry to bother the list with this question - I know people are always asking it. I thought I understood how to do this, but my code doesn't work. I am trying to save a java object in a database using the setBytes() method of PreparedStatement - I don't want to use the large object manager because I want this to be somewhat portable. The code below gives me the error: Exception: FastPath protocol error: Z :: FastPath protocol error: Z As soon as I call setBytes() I thought this only came when you forget to call "setAutoCommit(false)". Can anyone please tell me what I'm doing wrong. Thanks a lot, Rob -------------------- PSQLTest.java ----------------------- import java.sql.* ; import java.io.* ; import java.util.* ; public class PSQLTest { public PSQLTest() { } public static void main(String[] args) { Vector vec = new Vector() ;for (int i=0; i<10; ++i) vec.addElement(new Integer(i+5)) ; Connection conn = null ;try { Class.forName("postgresql.Driver") ; conn = DriverManager.getConnection ("jdbc:postgresql://127.0.0.1:5432/rob","rob", "") ; conn.setAutoCommit(false); byte[] bytes ; ByteArrayOutputStream out = new ByteArrayOutputStream() ; ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(vec) ; objOut.flush() ; bytes = out.toByteArray() ; objOut.close(); PreparedStatement ps = conn.prepareStatement ("insert into vectors (name, id) values ( ?, ?)") ; ps.setString(1, "Vector name") ; ps.setBytes(2, bytes) ; ps.executeUpdate() ; ps.close() ; conn.commit() ;} catch (Exception e) { System.out.println("Exception: "+e+" :: "+e.getMessage()); e.printStackTrace();} } }
pgsql-interfaces by date: