Re: Connection.setBytes()

From: Matt Fair <matt(at)netasol(dot)com>
To: Joachim Achtzehnter <joachim(at)kraut(dot)bc(dot)ca>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Connection.setBytes()
Date: 2000-07-18 19:08:49
Message-ID: 3974AB40.2892E26B@netasol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-novice

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)

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message ChristophSchmidt 2000-07-18 19:32:31 Re: Connection.setBytes()
Previous Message ChristophSchmidt 2000-07-18 19:06:06 Re: [INTERFACES] Connection.setBytes()

Browse pgsql-novice by date

  From Date Subject
Next Message ChristophSchmidt 2000-07-18 19:32:31 Re: Connection.setBytes()
Previous Message ChristophSchmidt 2000-07-18 19:06:06 Re: [INTERFACES] Connection.setBytes()