pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Matt Fair <matt@netasol.com>
To: Joachim Achtzehnter <joachim@kraut.bc.ca>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: Connection.setBytes()
Date: Tue, 18 Jul 2000 14:08:49 -0500
Message-ID: <3974AB40.2892E26B@netasol.com> (raw)
References: <Pine.WNT.4.21.0007181149250.131-100000@van4>

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.<init>(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)





view thread (12+ messages)  latest in thread

Message-ID: <3974AB40.2892E26B@netasol.com>
Permalink:  ../3974AB40.2892E26B@netasol.com/
Also on:    postgresql.org/message-id/3974AB40.2892E26B@netasol.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: matt@netasol.com, joachim@kraut.bc.ca
  Subject: Re: Connection.setBytes()
  In-Reply-To: <3974AB40.2892E26B@netasol.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox