Re: Connection.setBytes()
От | Matt Fair |
---|---|
Тема | Re: Connection.setBytes() |
Дата | |
Msg-id | 3974AB40.2892E26B@netasol.com обсуждение исходный текст |
Ответ на | Re: Connection.setBytes() (Joachim Achtzehnter <joachim@kraut.bc.ca>) |
Ответы |
Re: Connection.setBytes()
|
Список | pgsql-interfaces |
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("INSERTINTO 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("SQLException : " + 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.NullPointerExceptionat 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)
В списке pgsql-interfaces по дате отправления: