From: johann at 2ndquadrant.com (Johann 'Myrkraverk' Oskarsson) Date: Thu, 24 May 2012 09:07:43 +0000 Subject: [Pljava-dev] null pointer exception in pl/java jdbc driver In-Reply-To: (Richard Welty's message of "Mon, 14 May 2012 15:16:22 -0400") References: Message-ID: "Welty, Richard" writes: > i'm having trouble chasing down what may be close to the last bug in > my pl/ java code, a null pointer when executing an update. are there > restrictions on what i can do inside a function with this jdbc driver? > at this point, the code has successfully done a select, found the rows > it wants and issued an http request to a solr search engine; now it > needs to delete the rows that triggered the successful update: > > the method: The following code works for me. Can you give us the steps you are taking? package com2ndQuadrant.pljava; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Statement; import java.sql.SQLException; import java.util.List; import java.util.LinkedList; import java.util.logging.Logger; public class Update { public static void delete( Connection c, String key, List< Integer > ids ) throws SQLException { String s = ids.toString(); s = s.substring( 1, s.length() - 1 ); Logger l = Logger.getAnonymousLogger(); l.fine( s ); String r = "delete from t where key = '" + key + "' and id in ( " + s + " ) "; l.fine( r ); Statement stm = c.createStatement(); stm.execute( r ); } public static void doStuff( String key ) throws SQLException { Connection c = DriverManager.getConnection ( "jdbc:default:connection" ); List< Integer > l = new LinkedList< Integer >(); l.add( 3 ); l.add( 5 ); l.add( 7 ); delete( c, key, l ); } } -- Johann Oskarsson http://www.2ndquadrant.com/ |[] PostgreSQL Development, 24x7 Support, Training and Services --+-- | Blog: http://my.opera.com/myrkraverk/blog/