pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed"This ResultSet is closed" exception on a PreparedStatement getMetaData()
6+ messages / 3 participants
[nested] [flat]
* "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-19 09:33 Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
0 siblings, 2 replies; 6+ messages in thread
From: Emmanuel GUITON @ 2013-12-19 09:33 UTC (permalink / raw)
To: pgsql-jdbc
Hello,
I ran into troubles fetching metadata on a PreparedStatement. After some time, I isolated a simple test case that shows the issue (see the code snippet below). On a brand new PreparedStatement, I call the getMetaData() method without any problem. However, if I execute the query (executeQuery()) on this same statement, close the ResultSet and then calls again
getMetaData() (still on the same PreparedStatement), getMetaData() throws a RuntimeException saying "This ResultSet is closed".
I would expect to be able to get the metadata. Is that a bug in the JDBC driver ?
I tested this behavior on several flavours of the 9.3 driver version, including 9.3-1100-jdbc4 .
Regards,
- Emmanuel
package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import junit.framework.Assert;
import org.testng.annotations.Test;
/**
* Test on the PostgreSql JDBC driver.
*/
public class JdbcTest
{
/**
* This test shows a driver issue on the PreparedStatement management.
*
* @throws ClassNotFoundException On driver initialization failure.
* @throws SQLException On datbase operation failure.
*/
@Test
public void test2()
throws SQLException, ClassNotFoundException
{
Class.forName("org.postgresql.Driver");
final Connection connection = DriverManager.getConnection("jdbc:postgresql://server/db_name", "username", "password");
final String query = "SELECT 1 AS toto, 2 AS titi";
final PreparedStatement pstmt = connection.prepareStatement(query);
final ResultSetMetaData rsMetadata = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata);
final ResultSetMetaData rsMetadata2 = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata2);
final ResultSet rs = pstmt.executeQuery();
Assert.assertNotNull(rs);
rs.close();
Assert.assertFalse(pstmt.isClosed());
try
{
// Guess what ? The next line throws an exception !
final ResultSetMetaData rsMetadata3 = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata3);
}
catch (final RuntimeException exception)
{
Assert.fail(exception.getMessage());
}
pstmt.close();
connection.close();
}
}
Emmanuel GUITON
Ingénieur Développement
Fixe : +33170928416 • Standard : +33141917777
215, avenue Georges Clemenceau • 92024 Nanterre
[cid:imagea09388.JPG@42c04539.4396f69c]<http://http://www.forum-fic.com/2014/fr/inscription-fic/;
[cid:imagea9e219.JPG@8ae5650e.41802064]<http://www.intrinsec.com/;
Attachments:
imagea09388.JPG (image/jpeg, 14.9K) download
view image
imagea9e219.JPG (image/jpeg, 4.2K) download
view image
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-19 13:35 Dave Cramer <pg@fastcrypt.com>
parent: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
1 sibling, 1 reply; 6+ messages in thread
From: Dave Cramer @ 2013-12-19 13:35 UTC (permalink / raw)
To: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>; +Cc: pgsql-jdbc
Emmanuel,
The assumption that the spec makes about the prepared statement being
compiled are not valid for PostgreSQL. The metadata comes from the result
set, not from the statement. You could in fact not call getMetaData on a
statement which was not executed.
That being said, do you know if this behaviour is consistent with previous
versions of the JDBC driver ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Thu, Dec 19, 2013 at 4:33 AM, Emmanuel GUITON <
Emmanuel.GUITON@intrinsec.com> wrote:
> Hello,
>
> I ran into troubles fetching metadata on a PreparedStatement. After some
> time, I isolated a simple test case that shows the issue (see the code
> snippet below). On a brand new PreparedStatement, I call the getMetaData()
> method without any problem. However, if I execute the query
> (executeQuery()) on this same statement, close the ResultSet and then calls
> again
> getMetaData() (still on the same PreparedStatement), getMetaData() throws
> a RuntimeException saying "This ResultSet is closed".
> I would expect to be able to get the metadata. Is that a bug in the JDBC
> driver ?
>
> I tested this behavior on several flavours of the 9.3 driver version,
> including 9.3-1100-jdbc4 .
>
> Regards,
> - Emmanuel
>
>
> package test;
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.ResultSetMetaData;
> import java.sql.SQLException;
> import junit.framework.Assert;
> import org.testng.annotations.Test;
>
> /**
> * Test on the PostgreSql JDBC driver.
> */
> public class JdbcTest
> {
> /**
> * This test shows a driver issue on the PreparedStatement management.
> *
> * @throws ClassNotFoundException On driver initialization failure.
> * @throws SQLException On datbase operation failure.
> */
> @Test
> public void test2()
> throws SQLException, ClassNotFoundException
> {
> Class.forName("org.postgresql.Driver");
> final Connection connection =
> DriverManager.getConnection("jdbc:postgresql://server/db_name", "username",
> "password");
>
> final String query = "SELECT 1 AS toto, 2 AS titi";
>
> final PreparedStatement pstmt = connection.prepareStatement(query);
> final ResultSetMetaData rsMetadata = pstmt.getMetaData();
> Assert.assertNotNull(rsMetadata);
>
> final ResultSetMetaData rsMetadata2 = pstmt.getMetaData();
> Assert.assertNotNull(rsMetadata2);
>
> final ResultSet rs = pstmt.executeQuery();
> Assert.assertNotNull(rs);
> rs.close();
>
> Assert.assertFalse(pstmt.isClosed());
> try
> {
> // Guess what ? The next line throws an exception !
> final ResultSetMetaData rsMetadata3 = pstmt.getMetaData();
> Assert.assertNotNull(rsMetadata3);
> }
> catch (final RuntimeException exception)
> {
> Assert.fail(exception.getMessage());
> }
> pstmt.close();
>
> connection.close();
> }
> }
>
>
>
>
> *Emmanuel GUITON*
>
> *Ingénieur Développement *
> Fixe : +33170928416 l Standard : +33141917777
>
> 215, avenue Georges Clemenceau l 92024 Nanterre
>
> <http://http://www.forum-fic.com/2014/fr/inscription-fic/;
> <http://www.intrinsec.com/;
>
>
>
>
Attachments:
imagea9e219.JPG (image/jpeg, 4.2K) download
view image
imagea09388.JPG (image/jpeg, 14.9K) download
view image
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-19 13:59 Kevin Grittner <kgrittn@ymail.com>
parent: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
1 sibling, 0 replies; 6+ messages in thread
From: Kevin Grittner @ 2013-12-19 13:59 UTC (permalink / raw)
To: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>; pgsql-jdbc
Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com> wrote:
> On a brand new PreparedStatement, I call the getMetaData() method
> without any problem. However, if I execute the query
> (executeQuery()) on this same statement, close the ResultSet and
> then calls again getMetaData() (still on the same
> PreparedStatement), getMetaData() throws a RuntimeException
> saying "This ResultSet is closed".
> I would expect to be able to get the metadata. Is that a bug in
> the JDBC driver ?
It sure looks like a bug to me. Thanks for providing a clear,
self-contained test case. (It would make a good addition to our
unit tests once the bug is fixed.)
--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-19 14:06 Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 1 reply; 6+ messages in thread
From: Emmanuel GUITON @ 2013-12-19 14:06 UTC (permalink / raw)
To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc
Hi Dave,
I am a bit surprised with what you say since in the test case I provided, I call getMetaData() on the PreparedStatement without having ever executed the PreparedStatement itself to get the ResultSet. And it works.
Do you mean that under the hook the PreparedStatement executes a query to be able to fetch the metadata ? (Then what would it be since a ResultSet could not be fetched without parameter values when the query has parameters.)
Unfortunately, I do not know if this behavior is consistent with previous versions of the JDBC driver.
Regards,
- Emmanuel
Emmanuel GUITON
Ingénieur Développement
Fixe : +33170928416 • Standard : +33141917777
215, avenue Georges Clemenceau • 92024 Nanterre
[cid:imagece5cb1.JPG@77aaa8f3.42bf0e2a]<http://www.forum-fic.com/2014/fr/inscription-fic/;
[cid:image125bfa.JPG@8bfdc9d8.438d38ce]<http://www.intrinsec.com/;
________________________________
From: davecramer@gmail.com <davecramer@gmail.com> on behalf of Dave Cramer <pg@fastcrypt.com>
Sent: Thursday, December 19, 2013 2:35 PM
To: Emmanuel GUITON
Cc: pgsql-jdbc@postgresql.org
Subject: Re: [JDBC] "This ResultSet is closed" exception on a PreparedStatement getMetaData()
Emmanuel,
The assumption that the spec makes about the prepared statement being compiled are not valid for PostgreSQL. The metadata comes from the result set, not from the statement. You could in fact not call getMetaData on a statement which was not executed.
That being said, do you know if this behaviour is consistent with previous versions of the JDBC driver ?
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
________________________________
On Thu, Dec 19, 2013 at 4:33 AM, Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com<mailto:Emmanuel.GUITON@intrinsec.com>> wrote:
Hello,
I ran into troubles fetching metadata on a PreparedStatement. After some time, I isolated a simple test case that shows the issue (see the code snippet below). On a brand new PreparedStatement, I call the getMetaData() method without any problem. However, if I execute the query (executeQuery()) on this same statement, close the ResultSet and then calls again
getMetaData() (still on the same PreparedStatement), getMetaData() throws a RuntimeException saying "This ResultSet is closed".
I would expect to be able to get the metadata. Is that a bug in the JDBC driver ?
I tested this behavior on several flavours of the 9.3 driver version, including 9.3-1100-jdbc4 .
Regards,
- Emmanuel
package test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import junit.framework.Assert;
import org.testng.annotations.Test;
/**
* Test on the PostgreSql JDBC driver.
*/
public class JdbcTest
{
/**
* This test shows a driver issue on the PreparedStatement management.
*
* @throws ClassNotFoundException On driver initialization failure.
* @throws SQLException On datbase operation failure.
*/
@Test
public void test2()
throws SQLException, ClassNotFoundException
{
Class.forName("org.postgresql.Driver");
final Connection connection = DriverManager.getConnection("jdbc:postgresql://server/db_name", "username", "password");
final String query = "SELECT 1 AS toto, 2 AS titi";
final PreparedStatement pstmt = connection.prepareStatement(query);
final ResultSetMetaData rsMetadata = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata);
final ResultSetMetaData rsMetadata2 = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata2);
final ResultSet rs = pstmt.executeQuery();
Assert.assertNotNull(rs);
rs.close();
Assert.assertFalse(pstmt.isClosed());
try
{
// Guess what ? The next line throws an exception !
final ResultSetMetaData rsMetadata3 = pstmt.getMetaData();
Assert.assertNotNull(rsMetadata3);
}
catch (final RuntimeException exception)
{
Assert.fail(exception.getMessage());
}
pstmt.close();
connection.close();
}
}
Emmanuel GUITON
Ingénieur Développement
Fixe : +33170928416<tel:%2B33170928416> • Standard : +33141917777<tel:%2B33141917777>
215, avenue Georges Clemenceau • 92024 Nanterre
[cid:imagea09388.JPG@42c04539.4396f69c]<http://http://www.forum-fic.com/2014/fr/inscription-fic/;
[cid:imagea9e219.JPG@8ae5650e.41802064]<http://www.intrinsec.com/;
Attachments:
imagea9e219.JPG (image/jpeg, 4.2K) download
view image
imagea09388.JPG (image/jpeg, 14.9K) download
view image
imagece5cb1.JPG (image/jpeg, 14.9K) download
view image
image125bfa.JPG (image/jpeg, 4.2K) download
view image
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-19 14:20 Dave Cramer <pg@fastcrypt.com>
parent: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
0 siblings, 1 reply; 6+ messages in thread
From: Dave Cramer @ 2013-12-19 14:20 UTC (permalink / raw)
To: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>; +Cc: pgsql-jdbc
Hi Emmanuel,
That's what I get for answering without checking the code! You are correct
and it does seem like a bug, and fairly easily fixed. I'll echo Kevin's
sentiments here.
Thanks!
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Thu, Dec 19, 2013 at 9:06 AM, Emmanuel GUITON <
Emmanuel.GUITON@intrinsec.com> wrote:
> Hi Dave,
>
> I am a bit surprised with what you say since in the test case I provided,
> I call getMetaData() on the PreparedStatement without having ever
> executed the PreparedStatement itself to get the ResultSet. And it works.
> Do you mean that under the hook the PreparedStatement executes a query to
> be able to fetch the metadata ? (Then what would it be since a ResultSet
> could not be fetched without parameter values when the query has
> parameters.)
>
> Unfortunately, I do not know if this behavior is consistent with previous
> versions of the JDBC driver.
>
> Regards,
> - Emmanuel
>
>
>
> *Emmanuel GUITON*
>
> *Ingénieur Développement *
> Fixe : +33170928416 l Standard : +33141917777
>
> 215, avenue Georges Clemenceau l 92024 Nanterre
>
> <http://www.forum-fic.com/2014/fr/inscription-fic/;
> <http://www.intrinsec.com/;
>
>
>
> ------------------------------
> *From:* davecramer@gmail.com <davecramer@gmail.com> on behalf of Dave
> Cramer <pg@fastcrypt.com>
> *Sent:* Thursday, December 19, 2013 2:35 PM
> *To:* Emmanuel GUITON
> *Cc:* pgsql-jdbc@postgresql.org
> *Subject:* Re: [JDBC] "This ResultSet is closed" exception on a
> PreparedStatement getMetaData()
>
>
> Emmanuel,
>
> The assumption that the spec makes about the prepared statement being
> compiled are not valid for PostgreSQL. The metadata comes from the result
> set, not from the statement. You could in fact not call getMetaData on a
> statement which was not executed.
>
> That being said, do you know if this behaviour is consistent with
> previous versions of the JDBC driver ?
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
>
>
> ------------------------------
>
> On Thu, Dec 19, 2013 at 4:33 AM, Emmanuel GUITON <
> Emmanuel.GUITON@intrinsec.com> wrote:
>
>> Hello,
>>
>> I ran into troubles fetching metadata on a PreparedStatement. After some
>> time, I isolated a simple test case that shows the issue (see the code
>> snippet below). On a brand new PreparedStatement, I call the getMetaData()
>> method without any problem. However, if I execute the query
>> (executeQuery()) on this same statement, close the ResultSet and then calls
>> again
>> getMetaData() (still on the same PreparedStatement), getMetaData() throws
>> a RuntimeException saying "This ResultSet is closed".
>> I would expect to be able to get the metadata. Is that a bug in the JDBC
>> driver ?
>>
>> I tested this behavior on several flavours of the 9.3 driver version,
>> including 9.3-1100-jdbc4 .
>>
>> Regards,
>> - Emmanuel
>>
>>
>> package test;
>>
>> import java.sql.Connection;
>> import java.sql.DriverManager;
>> import java.sql.PreparedStatement;
>> import java.sql.ResultSet;
>> import java.sql.ResultSetMetaData;
>> import java.sql.SQLException;
>> import junit.framework.Assert;
>> import org.testng.annotations.Test;
>>
>> /**
>> * Test on the PostgreSql JDBC driver.
>> */
>> public class JdbcTest
>> {
>> /**
>> * This test shows a driver issue on the PreparedStatement management.
>> *
>> * @throws ClassNotFoundException On driver initialization failure.
>> * @throws SQLException On datbase operation failure.
>> */
>> @Test
>> public void test2()
>> throws SQLException, ClassNotFoundException
>> {
>> Class.forName("org.postgresql.Driver");
>> final Connection connection =
>> DriverManager.getConnection("jdbc:postgresql://server/db_name", "username",
>> "password");
>>
>> final String query = "SELECT 1 AS toto, 2 AS titi";
>>
>> final PreparedStatement pstmt =
>> connection.prepareStatement(query);
>> final ResultSetMetaData rsMetadata = pstmt.getMetaData();
>> Assert.assertNotNull(rsMetadata);
>>
>> final ResultSetMetaData rsMetadata2 = pstmt.getMetaData();
>> Assert.assertNotNull(rsMetadata2);
>>
>> final ResultSet rs = pstmt.executeQuery();
>> Assert.assertNotNull(rs);
>> rs.close();
>>
>> Assert.assertFalse(pstmt.isClosed());
>> try
>> {
>> // Guess what ? The next line throws an exception !
>> final ResultSetMetaData rsMetadata3 = pstmt.getMetaData();
>> Assert.assertNotNull(rsMetadata3);
>> }
>> catch (final RuntimeException exception)
>> {
>> Assert.fail(exception.getMessage());
>> }
>> pstmt.close();
>>
>> connection.close();
>> }
>> }
>>
>>
>>
>>
>> *Emmanuel GUITON*
>>
>> *Ingénieur Développement *
>> Fixe : +33170928416 l Standard : +33141917777
>>
>> 215, avenue Georges Clemenceau l 92024 Nanterre
>>
>> <http://http://www.forum-fic.com/2014/fr/inscription-fic/;
>> <http://www.intrinsec.com/;
>>
>>
>>
>>
>
Attachments:
imagea9e219.JPG (image/jpeg, 4.2K) download
view image
image125bfa.JPG (image/jpeg, 4.2K) download
view image
imagea09388.JPG (image/jpeg, 14.9K) download
view image
imagece5cb1.JPG (image/jpeg, 14.9K) download
view image
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()
@ 2013-12-20 12:27 Dave Cramer <pg@fastcrypt.com>
parent: Dave Cramer <pg@fastcrypt.com>
0 siblings, 0 replies; 6+ messages in thread
From: Dave Cramer @ 2013-12-20 12:27 UTC (permalink / raw)
To: Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>; +Cc: pgsql-jdbc
Hi Emmanuel,
I've just pushed a fix into master for this. Thanks!
Dave Cramer
dave.cramer(at)credativ(dot)ca
http://www.credativ.ca
On Thu, Dec 19, 2013 at 9:20 AM, Dave Cramer <pg@fastcrypt.com> wrote:
> Hi Emmanuel,
>
> That's what I get for answering without checking the code! You are correct
> and it does seem like a bug, and fairly easily fixed. I'll echo Kevin's
> sentiments here.
>
> Thanks!
>
> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
> On Thu, Dec 19, 2013 at 9:06 AM, Emmanuel GUITON <
> Emmanuel.GUITON@intrinsec.com> wrote:
>
>> Hi Dave,
>>
>> I am a bit surprised with what you say since in the test case I provided,
>> I call getMetaData() on the PreparedStatement without having ever
>> executed the PreparedStatement itself to get the ResultSet. And it works.
>> Do you mean that under the hook the PreparedStatement executes a query to
>> be able to fetch the metadata ? (Then what would it be since a ResultSet
>> could not be fetched without parameter values when the query has
>> parameters.)
>>
>> Unfortunately, I do not know if this behavior is consistent with previous
>> versions of the JDBC driver.
>>
>> Regards,
>> - Emmanuel
>>
>>
>>
>> *Emmanuel GUITON*
>>
>> *Ingénieur Développement *
>> Fixe : +33170928416 l Standard : +33141917777
>>
>> 215, avenue Georges Clemenceau l 92024 Nanterre
>>
>> <http://www.forum-fic.com/2014/fr/inscription-fic/;
>> <http://www.intrinsec.com/;
>>
>>
>>
>> ------------------------------
>> *From:* davecramer@gmail.com <davecramer@gmail.com> on behalf of Dave
>> Cramer <pg@fastcrypt.com>
>> *Sent:* Thursday, December 19, 2013 2:35 PM
>> *To:* Emmanuel GUITON
>> *Cc:* pgsql-jdbc@postgresql.org
>> *Subject:* Re: [JDBC] "This ResultSet is closed" exception on a
>> PreparedStatement getMetaData()
>>
>>
>> Emmanuel,
>>
>> The assumption that the spec makes about the prepared statement being
>> compiled are not valid for PostgreSQL. The metadata comes from the result
>> set, not from the statement. You could in fact not call getMetaData on a
>> statement which was not executed.
>>
>> That being said, do you know if this behaviour is consistent with
>> previous versions of the JDBC driver ?
>>
>> Dave Cramer
>>
>> dave.cramer(at)credativ(dot)ca
>> http://www.credativ.ca
>>
>>
>>
>>
>> ------------------------------
>>
>> On Thu, Dec 19, 2013 at 4:33 AM, Emmanuel GUITON <
>> Emmanuel.GUITON@intrinsec.com> wrote:
>>
>>> Hello,
>>>
>>> I ran into troubles fetching metadata on a PreparedStatement. After some
>>> time, I isolated a simple test case that shows the issue (see the code
>>> snippet below). On a brand new PreparedStatement, I call the getMetaData()
>>> method without any problem. However, if I execute the query
>>> (executeQuery()) on this same statement, close the ResultSet and then calls
>>> again
>>> getMetaData() (still on the same PreparedStatement), getMetaData()
>>> throws a RuntimeException saying "This ResultSet is closed".
>>> I would expect to be able to get the metadata. Is that a bug in the JDBC
>>> driver ?
>>>
>>> I tested this behavior on several flavours of the 9.3 driver version,
>>> including 9.3-1100-jdbc4 .
>>>
>>> Regards,
>>> - Emmanuel
>>>
>>>
>>> package test;
>>>
>>> import java.sql.Connection;
>>> import java.sql.DriverManager;
>>> import java.sql.PreparedStatement;
>>> import java.sql.ResultSet;
>>> import java.sql.ResultSetMetaData;
>>> import java.sql.SQLException;
>>> import junit.framework.Assert;
>>> import org.testng.annotations.Test;
>>>
>>> /**
>>> * Test on the PostgreSql JDBC driver.
>>> */
>>> public class JdbcTest
>>> {
>>> /**
>>> * This test shows a driver issue on the PreparedStatement
>>> management.
>>> *
>>> * @throws ClassNotFoundException On driver initialization failure.
>>> * @throws SQLException On datbase operation failure.
>>> */
>>> @Test
>>> public void test2()
>>> throws SQLException, ClassNotFoundException
>>> {
>>> Class.forName("org.postgresql.Driver");
>>> final Connection connection =
>>> DriverManager.getConnection("jdbc:postgresql://server/db_name", "username",
>>> "password");
>>>
>>> final String query = "SELECT 1 AS toto, 2 AS titi";
>>>
>>> final PreparedStatement pstmt =
>>> connection.prepareStatement(query);
>>> final ResultSetMetaData rsMetadata = pstmt.getMetaData();
>>> Assert.assertNotNull(rsMetadata);
>>>
>>> final ResultSetMetaData rsMetadata2 = pstmt.getMetaData();
>>> Assert.assertNotNull(rsMetadata2);
>>>
>>> final ResultSet rs = pstmt.executeQuery();
>>> Assert.assertNotNull(rs);
>>> rs.close();
>>>
>>> Assert.assertFalse(pstmt.isClosed());
>>> try
>>> {
>>> // Guess what ? The next line throws an exception !
>>> final ResultSetMetaData rsMetadata3 = pstmt.getMetaData();
>>> Assert.assertNotNull(rsMetadata3);
>>> }
>>> catch (final RuntimeException exception)
>>> {
>>> Assert.fail(exception.getMessage());
>>> }
>>> pstmt.close();
>>>
>>> connection.close();
>>> }
>>> }
>>>
>>>
>>>
>>>
>>> *Emmanuel GUITON*
>>>
>>> *Ingénieur Développement *
>>> Fixe : +33170928416 l Standard : +33141917777
>>>
>>> 215, avenue Georges Clemenceau l 92024 Nanterre
>>>
>>> <http://http://www.forum-fic.com/2014/fr/inscription-fic/;
>>> <http://www.intrinsec.com/;
>>>
>>>
>>>
>>>
>>
>
Attachments:
imagece5cb1.JPG (image/jpeg, 14.9K) download
view image
imagea9e219.JPG (image/jpeg, 4.2K) download
view image
image125bfa.JPG (image/jpeg, 4.2K) download
view image
imagea09388.JPG (image/jpeg, 14.9K) download
view image
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2013-12-20 12:27 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-12-19 09:33 "This ResultSet is closed" exception on a PreparedStatement getMetaData() Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
2013-12-19 13:35 ` Dave Cramer <pg@fastcrypt.com>
2013-12-19 14:06 ` Emmanuel GUITON <Emmanuel.GUITON@intrinsec.com>
2013-12-19 14:20 ` Dave Cramer <pg@fastcrypt.com>
2013-12-20 12:27 ` Dave Cramer <pg@fastcrypt.com>
2013-12-19 13:59 ` Kevin Grittner <kgrittn@ymail.com>
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