Received: from cda.mrs.umn.edu (root@cda.mrs.umn.edu [146.57.3.11]) by hub.org (8.10.1/8.10.1) with ESMTP id e6IJ8bh74487 for ; Tue, 18 Jul 2000 15:08:37 -0400 (EDT) Received: from netasol.com (ctrts1-3.mrs.umn.edu [146.57.4.203]) by cda.mrs.umn.edu (8.10.0/8.10.0) with ESMTP id e6IJ8W127225; Tue, 18 Jul 2000 14:08:33 -0500 (CDT) Message-ID: <3974AB40.2892E26B@netasol.com> Date: Tue, 18 Jul 2000 14:08:49 -0500 From: Matt Fair Organization: Netasol Networks, Inc. X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.14-5.0 i586) X-Accept-Language: en MIME-Version: 1.0 To: Joachim Achtzehnter CC: pgsql-interfaces@postgresql.org Subject: Re: Connection.setBytes() References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200007/126 Here is the code I am using: import java.sql.*; import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import org.postgresql.largeobject.*; import org.postgresql.util.*; class PsqlConsole { private Connection con; private Statement stmt; private PreparedStatement ps; public PsqlConsole(String url) { try{ //load the db driver Class.forName("org.postgresql.Driver"); //get a connection to the database System.out.println("jdbc:postgresql://"+url); con = DriverManager.getConnection("jdbc:postgresql://"+url, "matt", "matt"); con.setAutoCommit(false); } catch(ClassNotFoundException e) { System.out.println("Could not load the following database driver:" + e.getMessage()); } catch(SQLException e) { System.out.println("SQLException caught: " + e.getMessage()); } finally { //always close the database try { if(con != null) con.close(); } catch(SQLException ignored) { } } } public void prompt() throws SQLException, IOException{ String description = new String(".........4000 Bytes......."); PreparedStatement pstmt = con.prepareStatement("INSERT INTO mytable (str) VALUES (?)"); pstmt.setBytes(1,description.getBytes()); //Line 49 pstmt.executeUpdate(); pstmt.close(); } public static void main(String[] args) { if(args.length > 0){ String url = args[0]; System.out.println("Connecting to " + url); PsqlConsole c = new PsqlConsole(url); try{ c.prompt(); }catch(SQLException e){ System.out.println("SQL Exception : " + e); }catch(IOException e){ System.out.println("Error in description"); } }else{ System.out.println("Usage: java PsqlConsole [url]"); System.out.println("url = www.domain.com/databasename"); } } } Here is the output I get (note, I cleaned up some things so the lines are a bit different below) Connecting to gecko/companywaterloo jdbc:postgresql://gecko/companywaterloo Exception in thread "main" java.lang.NullPointerException at org.postgresql.Connection.ExecSQL(Connection.java:312) at org.postgresql.jdbc2.Statement.execute(Statement.java:273) at org.postgresql.jdbc2.Statement.executeQuery(Statement.java:54) at org.postgresql.largeobject.LargeObjectManager.(LargeObjectManager.java:106) at org.postgresql.Connection.getLargeObjectAPI(Connection.java:561) at org.postgresql.jdbc2.PreparedStatement.setBytes(PreparedStatement.java:297) at PsqlConsole.prompt(PsqlConsole.java:49) at PsqlConsole.main(PsqlConsole.java:62)