PSQLException:此ResultSet已关闭Postgresql db

时间:2018-03-08 09:13:58

标签: java resultset worldwind

我正在开发NASA World Wind代码。基本思想是创建一个画布地图并创建与PostgreSQL数据库中的空间表(Shape文件)的连接,并在地图上删除一个地标。我正在调用结果集并执行查询。我知道结果集必须放在一个表中才能使用,因为一旦连接关闭,set就会变为null。我试过了,但它有一个完全不同的错误。

// CODE BLOCK //
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public Main()
    {
        Connection connection = null;
        Statement statement = null;
        ResultSet rs = null;
        String url = "jdbc:postgresql://localhost/<db name>";
        String user = "postgres";
        String password = "postgres";

        String query = "SELECT gid, state_code, state_name, district_c, district_n, sub_distri, town_code, town_name, ST_X(geom), ST_Y(geom) FROM indiacity";

            try
            {
                connection = DriverManager.getConnection(url, user, password);
                System.out.println(" DATABASE CONNECTION SUCCESSFUL. ");
                statement = connection.createStatement();
                rs = statement.executeQuery(query);
                System.out.println(rs);
            }
            catch (SQLException ex)
            {
                ex.printStackTrace();
            }
            finally
            {
                try
                {
                    if (rs != null)
                    {
                        rs.close();
                    }
                    if (statement != null)
                    {
                        statement.close();
                    }
                    if (connection != null)
                    {
                        connection.close();
                    }
                }
                catch (SQLException ex)
                {
                    ex.printStackTrace();
                }
            }
world = new WorldWindowGLCanvas();
        world.setPreferredSize(new java.awt.Dimension(1000, 800));
        this.getContentPane().add(world, BorderLayout.CENTER);
        world.setModel(new BasicModel());
        final RenderableLayer layer = new RenderableLayer();
        PointPlacemark placemark = null;
        try
        {
            placemark = new PointPlacemark(Position.fromDegrees(rs.getDouble(10), rs.getDouble(10), 10));
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        // pp = new PointPlacemark(Position.fromDegrees(30, -103.5, 2e3));
        placemark.setLabelText("PLACEMARK");
        placemark.setValue(AVKey.DISPLAY_NAME, "All defaults");
        layer.addRenderable(placemark);
        propertiesLayer = new RenderableLayer();
        LayerList layers = world.getModel().getLayers();
        layers.add(propertiesLayer);
        layers.add(layer);

 public static void main (String [] args)
    {
        // TODO Auto-generated method stub
     java.awt.EventQueue.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                JFrame frame = new Main();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setName("POSTGRESQL DB EXAMPLE");
                frame.pack();
                frame.setVisible(true);
            }
        });
    }
}

// ERROR BLOCK //

 DATABASE CONNECTION SUCCESSFUL.

    org.postgresql.jdbc.PgResultSet@16904c4
    org.postgresql.util.PSQLException: This ResultSet is closed.
        at org.postgresql.jdbc.PgResultSet.checkClosed(PgResultSet.java:2737)
        at org.postgresql.jdbc.PgResultSet.checkResultSet(PgResultSet.java:2765)
        at org.postgresql.jdbc.PgResultSet.getDouble(PgResultSet.java:2303)
        at avr_package.Main.<init>(Main.java:101)
        at avr_package.Main$1.run(Main.java:184)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
        at avr_package.Main.<init>(Main.java:108)
        at avr_package.Main$1.run(Main.java:184)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
        at java.awt.EventQueue.access$000(EventQueue.java:101)
        at java.awt.EventQueue$3.run(EventQueue.java:666)
        at java.awt.EventQueue$3.run(EventQueue.java:664)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Mar 08, 2018 2:38:24 PM gov.nasa.worldwind.util.SessionCacheRetrievalPostProcessor run
    SEVERE: Retrieval returned no content for https://worldwind20.arc.nasa.gov/mapcache?EXCEPTIONS=application/vnd.ogc.se_xml&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0

    Process finished with exit code 0

所有帮助都是适当的。

0 个答案:

没有答案