public inbox for [email protected]  
help / color / mirror / Atom feed
[Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement?
6+ messages / 0 participants
[nested] [flat]

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement?
@ 2008-06-04 11:37 
  2008-06-04 15:34 ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
  0 siblings, 1 reply; 6+ messages in thread

From:  @ 2008-06-04 11:37 UTC (permalink / raw)

Dear PL/Java Team

Thank you for PL/Java, it is a great tool!

However, this post is about a problem that occurs since switching from
PL/Java 1.3.0 to 1.4.0 (forced by migrating to a new PostgreSQL
version). 
It would be very nice if somebody could have a look at it. I think it is
a bug in 1.4.0. Thank you:-)

When executing SQL queries inside PL/Java functions it seems that the
java.sql.Statement now gets automatically closed by
Statement.executeQuery(). This leads to a SQLException: "statement is
closed" when calling Statement.getWarnings() afterwards. This behavior
is new in 1.4.0 (tested both on PostgreSQL 8.3.1 and 8.1.11). 
[This is exactly what the Spring class JdbcTemplate - which I am forced
to use in this context - does in a query: executeQuery() and then
getWarnings(). Therefore simply not calling getWarnings() is not an
option for my problem.]

Here is an example function to reproduce the SQLException:

--- SNIP --- test class to create a jar from:

import java.sql.*;
import java.util.logging.*;

public class PlJavaTest
{
    private static void doTest() throws Exception
    {
        Connection connection =
DriverManager.getConnection("jdbc:default:connection");
        Statement statement = connection.createStatement();
        ResultSet rs = statement.executeQuery("SELECT * FROM
information_schema.tables");

        try {
            // this will throw a SQLException:
            statement.getWarnings();
        }
        catch (Exception e) {
            Logger.getAnonymousLogger().log(Level.SEVERE, "Caught
exception in getWarnings()", e);
            throw e;
        }
    }
}

--- SNIP --- SQL commands to install the jar and call the test PL/Java
function:

# select sqlj.remove_jar('pljavatest', false);
select sqlj.install_jar('file:///.../pljavatest.jar', 'pljavatest',
false);
select sqlj.set_classpath('public', 'pljavatest');
create or replace function pljavatest() returns void as
'PlJavaTest.doTest' language 'java' volatile;
select pljavatest();

--- SNIP --- output of last SQL command:

pljavatest=# select pljavatest();
ERROR:  04 Jun 08 13:25:26 PlJavaTest Caught exception in getWarnings()
java.sql.SQLException: getWarnings: Statement is closed
        at
org.postgresql.pljava.jdbc.SPIStatement.getWarnings(SPIStatement.java:31
4)
        at PlJavaTest.doTest(PlJavaTest.java:14)

--- SNIP ---

As a workaround I am currently using wrapper classes around the original
Connection and Statement which override the getWarnings() method. This
works but is certainly not a clean solution...

Regards
Holger Fleischmann

Achtung: Neue E-Mail-Adresse! Attention: New e-mail-address! holger.fleischmann at manroland.com

Sollten Sie nicht der vorgesehene Empfanger sein, so bitten wir hoflich um eine Mitteilung und um Loschung der Nachricht.
Vielen Dank fur Ihre Unterstutzung.
If you are not the addressee, please inform us immediately that you have received this e-mail by mistake, and delete it.
We thank you for your support. 

--------------------------------------------------------
manroland AG
Vorsitzender des Aufsichtsrates: Hanno C. Fiedler
Vorstand: Gerd Finkbeiner (Vorsitzender), Dr. Ingo Koch, Dr. Markus Rall, Paul Steidle
Sitz der Gesellschaft: Offenbach am Main, Registergericht: Amtsgericht Offenbach HRB-Nr. 42592
USt-Ident-Nr. DE 250200933




^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement?
  2008-06-04 11:37 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
@ 2008-06-04 15:34 ` 
  2008-06-05 10:11   ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
  0 siblings, 1 reply; 6+ messages in thread

From:  @ 2008-06-04 15:34 UTC (permalink / raw)

holger.fleischmann at manroland.com wrote:
> 
> When executing SQL queries inside PL/Java functions it seems that the
> java.sql.Statement now gets automatically closed by
> Statement.executeQuery(). This leads to a SQLException: "statement is
> closed" when calling Statement.getWarnings() afterwards.

I've applied the attached patch to CVS to fix this problem.  Thanks for 
the complete report and test case.

Kris Jurka

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dont-close-statement.patch
Type: text/x-patch
Size: 2721 bytes
Desc: not available
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20080604/a9b9dd08/attachment.bin;



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement?
  2008-06-04 11:37 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
  2008-06-04 15:34 ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
@ 2008-06-05 10:11   ` 
  0 siblings, 0 replies; 6+ messages in thread

From:  @ 2008-06-05 10:11 UTC (permalink / raw)

Hi Kris

> I've applied the attached patch to CVS to fix this problem.  

Thank you for your very quick reaction and for the patch! I've just
tested the patched version: it does work now.

Regards
Holger Fleischmann

Achtung: Neue E-Mail-Adresse! Attention: New e-mail-address! holger.fleischmann at manroland.com

Sollten Sie nicht der vorgesehene Empfanger sein, so bitten wir hoflich um eine Mitteilung und um Loschung der Nachricht.
Vielen Dank fur Ihre Unterstutzung.
If you are not the addressee, please inform us immediately that you have received this e-mail by mistake, and delete it.
We thank you for your support. 

--------------------------------------------------------
manroland AG
Vorsitzender des Aufsichtsrates: Hanno C. Fiedler
Vorstand: Gerd Finkbeiner (Vorsitzender), Dr. Ingo Koch, Dr. Markus Rall, Paul Steidle
Sitz der Gesellschaft: Offenbach am Main, Registergericht: Amtsgericht Offenbach HRB-Nr. 42592
USt-Ident-Nr. DE 250200933





^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux
@ 2010-03-07 19:33 
  2010-03-12 13:35 ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
  0 siblings, 1 reply; 6+ messages in thread

From:  @ 2010-03-07 19:33 UTC (permalink / raw)

I've been tracking down a problem where checking getWarnings() after an
executeQuery() in pljava and found an exchange on the list from 2008
that matches my symptoms exactly:

http://pgfoundry.org/pipermail/pljava-dev/2008/001298.html
<http://pgfoundry.org/pipermail/pljava-dev/2008/001303.html;

Kris Jurka replied swiftly and fixed the issue in the source tree. Was
this ever released live? I've just downloaded the latest:

http://pgfoundry.org/frs/download.php/1597/pljava-i686-pc-linux-gnu-pg8.2-1.4.0.tar.gz

To run against our PG 8.2.15 database and I'm still getting the problem.

-- 
Tim Clarke AMBCS MIAP
IT Director
Manifest
9 Freebournes Court
Newland Street
Witham, Essex
CM8 2BL
England
 
Phone: +44 1376 503500
Direct: +44 1376 504510
Fax: +44 1376 503550
Email: tim.clarke at manifest.co.uk <mailto:tim.clarke at manifest.co.uk>
Web: http://www.manifest.co.uk
Skype: callto:tim.clarke

Manifest is the trading name of: Manifest Information Services Ltd: Registered in England Number 3401145 & The Manifest Voting Agency Ltd:
Registered in England Number 2920820. Registered Office at above address. VAT Registration Number: GB 700 1880 77
Copyright: This e-mail may contain confidential or legally privileged information.
If you are not the named addressee you must not use or disclose such information, instead please report it to: admin at manifest.co.uk 
Please see http://www.manifest.co.uk/legal/legal_notices.htm for further information.






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux
  2010-03-07 19:33 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
@ 2010-03-12 13:35 ` 
  2010-03-22 12:29   ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
  0 siblings, 1 reply; 6+ messages in thread

From:  @ 2010-03-12 13:35 UTC (permalink / raw)

>
> I've been tracking down a problem where checking getWarnings() after an
> executeQuery() in pljava and found an exchange on the list from 2008
> that matches my symptoms exactly:
>
> http://pgfoundry.org/pipermail/pljava-dev/2008/001298.html
> <http://pgfoundry.org/pipermail/pljava-dev/2008/001303.html;
>
> Kris Jurka replied swiftly and fixed the issue in the source tree. Was
> this ever released live? I've just downloaded the latest:
>
> http://pgfoundry.org/frs/download.php/1597/pljava-i686-pc-linux-gnu-pg8.2-1.4.0.tar.gz
>
> To run against our PG 8.2.15 database and I'm still getting the problem.
>
>   

I (think) I've managed to get a compile now using Eclipse and jdk1.5_10.
Unfortunately when registering my java function calls using

set search_path=voting;

select sqlj.install_jar('file:///usr/local/manifest/vote.jar',
  'vote', false);
select sqlj.install_jar('file:///usr/share/java/log4j.jar',
  'log4j', false);
SELECT sqlj.set_classpath('voting', 'vote:log4j');

CREATE or replace FUNCTION vote(AccountID int8, CapitalID int8,
  EventID int8, CanCopy bool, CopyFromEventID int8)
  RETURNS varchar
  AS 'uk.co.manifest.postgres.vote.VoteCalc.vote(long, long, long,
boolean, long)'
  volatile LANGUAGE java;

I get the error:

java.lang.NoSuchMethodError: Method org.postgresql.pljava.internal.Portal._
fetch(JZI)I

on that first install_jar() call followed by "failed to create JVM" on
any subsequent calls :-/ I've not found an answer by googling. Can
anyone help?

-- 
Tim Clarke AMBCS MIAP
IT Director
Manifest
9 Freebournes Court
Newland Street
Witham, Essex
CM8 2BL
England
 
Phone: +44 1376 503500
Direct: +44 1376 504510
Fax: +44 1376 503550
Email: tim.clarke at manifest.co.uk <mailto:tim.clarke at manifest.co.uk>
Web: http://www.manifest.co.uk
Skype: callto:tim.clarke

Manifest is the trading name of: Manifest Information Services Ltd: Registered in England Number 3401145 & The Manifest Voting Agency Ltd:
Registered in England Number 2920820. Registered Office at above address. VAT Registration Number: GB 700 1880 77
Copyright: This e-mail may contain confidential or legally privileged information.
If you are not the named addressee you must not use or disclose such information, instead please report it to: admin at manifest.co.uk 
Please see http://www.manifest.co.uk/legal/legal_notices.htm for further information.






^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux
  2010-03-07 19:33 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
  2010-03-12 13:35 ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
@ 2010-03-22 12:29   ` 
  0 siblings, 0 replies; 6+ messages in thread

From:  @ 2010-03-22 12:29 UTC (permalink / raw)

On 12/03/10 13:35, Tim Clarke wrote:
>> I've been tracking down a problem where checking getWarnings() after an
>> executeQuery() in pljava and found an exchange on the list from 2008
>> that matches my symptoms exactly:
>>
>> http://pgfoundry.org/pipermail/pljava-dev/2008/001298.html
>> <http://pgfoundry.org/pipermail/pljava-dev/2008/001303.html;
>>
>> Kris Jurka replied swiftly and fixed the issue in the source tree. Was
>> this ever released live? I've just downloaded the latest:
>>
>> http://pgfoundry.org/frs/download.php/1597/pljava-i686-pc-linux-gnu-pg8.2-1.4.0.tar.gz
>>
>> To run against our PG 8.2.15 database and I'm still getting the problem.
>>
>>   
>>     
> I (think) I've managed to get a compile now using Eclipse and jdk1.5_10.
> Unfortunately when registering my java function calls using
>
> set search_path=voting;
>
> select sqlj.install_jar('file:///usr/local/manifest/vote.jar',
>   'vote', false);
> select sqlj.install_jar('file:///usr/share/java/log4j.jar',
>   'log4j', false);
> SELECT sqlj.set_classpath('voting', 'vote:log4j');
>
> CREATE or replace FUNCTION vote(AccountID int8, CapitalID int8,
>   EventID int8, CanCopy bool, CopyFromEventID int8)
>   RETURNS varchar
>   AS 'uk.co.manifest.postgres.vote.VoteCalc.vote(long, long, long,
> boolean, long)'
>   volatile LANGUAGE java;
>
> I get the error:
>
> java.lang.NoSuchMethodError: Method org.postgresql.pljava.internal.Portal._
> fetch(JZI)I
>
> on that first install_jar() call followed by "failed to create JVM" on
> any subsequent calls :-/ I've not found an answer by googling. Can
> anyone help?
>   

Just for the record (the list's a bit quiet ;-) :

The answer was that the version of the pljava.so file was out of step. I
ran make from command line instead of trying to export from eclipse;
obviously that did not build the C object. I found the correct version
in the folder tree after running make at the command line.

-- 
Tim Clarke AMBCS MIAP
IT Director
Manifest
9 Freebournes Court
Newland Street
Witham, Essex
CM8 2BL
England
 
Phone: +44 1376 503500
Direct: +44 1376 504510
Fax: +44 1376 503550
Email: tim.clarke at manifest.co.uk <mailto:tim.clarke at manifest.co.uk>
Web: http://www.manifest.co.uk
Skype: callto:tim.clarke

Manifest is the trading name of: Manifest Information Services Ltd: Registered in England Number 3401145 & The Manifest Voting Agency Ltd:
Registered in England Number 2920820. Registered Office at above address. VAT Registration Number: GB 700 1880 77
Copyright: This e-mail may contain confidential or legally privileged information.
If you are not the named addressee you must not use or disclose such information, instead please report it to: admin at manifest.co.uk 
Please see http://www.manifest.co.uk/legal/legal_notices.htm for further information.







^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2010-03-22 12:29 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2008-06-04 11:37 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement? 
2008-06-04 15:34 ` 
2008-06-05 10:11   ` 
2010-03-07 19:33 [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
2010-03-12 13:35 ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 
2010-03-22 12:29   ` [Pljava-dev] Using JDBC in PL/Java 1.4.0: Statement.executeQuery() automatically closes the statement redux 

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