Received: from gade.imada.sdu.dk (postfix@gade.imada.sdu.dk [130.225.128.158]) by hub.org (8.9.3/8.9.3) with ESMTP id LAA61717 for ; Mon, 21 Jun 1999 11:16:39 -0400 (EDT) (envelope-from jews@imada.sdu.dk) From: jews@imada.sdu.dk Received: from medea.imada.sdu.dk (medea.imada.sdu.dk [130.225.128.143]) by gade.imada.sdu.dk (Postfix) with ESMTP id 42D701A for ; Mon, 21 Jun 1999 17:16:37 +0200 (MET DST) Received: (from jews@localhost) by medea.imada.sdu.dk (8.8.5/8.8.8) id RAA04732 for pgsql-interfaces@postgresql.org; Mon, 21 Jun 1999 17:16:36 +0200 Message-Id: <199906211516.RAA04732@medea.imada.sdu.dk> Subject: BLOBs and JDBC in PostgreSQL-6.5 To: pgsql-interfaces@postgresql.org Date: Mon, 21 Jun 1999 17:16:36 +0200 (MEST) X-Mailer: ELM [version 2.4ME+ PL31 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi. I hope that someone can help me with this problem. I can't get BLOBs to work with the JDBC driver :( I have the following program: ////////////////////////////////////////////////////////////////////// import java.io.*; import java.sql.*; import java.text.*; public class basic { Connection db; // The connection to the database Statement st; // Our statement to run queries with public basic() throws ClassNotFoundException, FileNotFoundException, IOException, SQLException { // Load the driver Class.forName("postgresql.Driver"); // Connect to database System.out.println("Connecting to Database URL = ddl"); db = DriverManager.getConnection("jdbc:postgresql:ddl", "ddl", "secret"); db.setAutoCommit(false); System.out.println("Connected..."); st = db.createStatement(); example(); st.executeUpdate("commit"); // Finally close the database System.out.println("Now closing the connection"); st.close(); db.close(); } public void example() throws SQLException { try { System.out.println("Creating table ..."); st.executeUpdate("drop table images"); st.executeUpdate("create table images (imgname name, imgoid oid)"); System.out.println("Creating file stream ..."); File file = new File("myimage.gif"); FileInputStream fis = new FileInputStream(file); System.out.println("Creating statement ..."); PreparedStatement ps = db.prepareStatement("insert into images values (?,?)"); System.out.println("1"); ps.setString(1,file.getName()); System.out.println("2"); ps.setBinaryStream(2,fis,(int)file.length()); System.out.println("3"); System.out.println("Executing statement ..."); ps.executeUpdate(); System.out.println("Closing statement ..."); ps.close(); fis.close(); } catch (IOException ex) { System.err.println("Exception caught.\n"+ex); ex.printStackTrace(); } } public static void main(String args[]) { System.out.println("PostgreSQL BLOB test"); DriverManager.setLogStream(System.err); // Now run the tests try { basic test = new basic(); } catch(Exception ex) { System.err.println("Exception caught.\n"+ex); ex.printStackTrace(); } } } ////////////////////////////////////////////////////////////////////// I get this when I run it: PostgreSQL BLOB test DriverManager.initialize: jdbc.drivers = null JDBC DriverManager initialized registerDriver: driver[className=postgresql.Driver,postgresql.Driver@da6f42d3] Connecting to Database URL = ddl DriverManager.getConnection("jdbc:postgresql:ddl") trying driver[className=postgresql.Driver,postgresql.Driver@da6f42d3] -- listing properties -- password=secret user=ddl PGDBNAME=ddl Protocol=postgresql Using postgresql.jdbc2.Connection getConnection returning driver[className=postgresql.Driver,postgresql.Driver@da6f42d3] Connected... Creating table ... Creating file stream ... Creating statement ... 1 2 Exception caught. java.lang.NullPointerException java.lang.NullPointerException at java.io.Writer.write(Compiled Code) at java.io.PrintStream.write(Compiled Code) at java.io.PrintStream.print(Compiled Code) at java.io.PrintStream.println(Compiled Code) at java.lang.Throwable.printStackTrace(Compiled Code) at java.sql.SQLException.(Compiled Code) at postgresql.util.PSQLException.(Compiled Code) at postgresql.jdbc2.PreparedStatement.setBinaryStream(Compiled Code) at basic.example(Compiled Code) at basic.(Compiled Code) at basic.main(Compiled Code) I tried Tatsuo Ishii patch to blobtest.java and it worked ok. But I want to use the native JDBC interface. Any ideas ? Cheers, Jesper Pedersen P.S. I'm not on the mailing-list.