"This ResultSet is closed" exception on a PreparedStatement getMetaData()

Поиск
Список
Период
Сортировка
От Emmanuel GUITON
Тема "This ResultSet is closed" exception on a PreparedStatement getMetaData()
Дата
Msg-id 624816662dca463f90adcce3a43c7c06@ISC-SRV-EXC05.Intrinsec.neurones.sa
обсуждение исходный текст
Ответы Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()  (Dave Cramer <pg@fastcrypt.com>)
Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()  (Kevin Grittner <kgrittn@ymail.com>)
Список 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 l Standard : +33141917777

215, avenue Georges Clemenceau l 92024 Nanterre


 

Вложения

В списке pgsql-jdbc по дате отправления:

Предыдущее
От: Dave Cramer
Дата:
Сообщение: Re: revisiting unix domain sockets
Следующее
От: Dave Cramer
Дата:
Сообщение: Re: "This ResultSet is closed" exception on a PreparedStatement getMetaData()