This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 136180 - DatabaseConnection.getJDBCConnection() returns null
Summary: DatabaseConnection.getJDBCConnection() returns null
Status: VERIFIED FIXED
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Andrei Badea
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-30 16:11 UTC by Andrei Badea
Modified: 2008-10-08 10:43 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Badea 2008-05-30 16:11:11 UTC
... just after connecting with ConnectionManager.showConnectionDialog(). Subsequent calls seem to return the
java.sql.Connection object as expected.
Comment 1 David Vancouvering 2008-06-03 18:25:04 UTC
Isn't this because showConnectionDialog() can potentially run asynchronously on a different thread?  Maybe we need a
showConnectionDialogFromEventThread() method?

    public void showConnectionDialog() {
        try {
            final ConnectionNodeInfo cni = findConnectionNodeInfo(getName());
            if (cni != null && cni.getConnection() == null) {
                Mutex.EVENT.readAccess(new Runnable() {
                    public void run() {
                        new ConnectAction.ConnectionDialogDisplayer().showDialog(cni, false);
                    }
                });
            }
        } catch (DatabaseException e) {
            Exceptions.printStackTrace(e);
        }
    }
Comment 2 Andrei Badea 2008-06-09 09:59:32 UTC
It is possible. In my case the behavior was caused by a bug in my code (outside the DB Explorer). So I can't really
reproduce the issue, so closing.
Comment 3 Prashant Ponnala 2008-08-21 01:37:41 UTC
The issue still exists in the latest netbeans. 
Product Version: NetBeans IDE 6.1 (Build 200805300101)

Invoking the same code second time around creates a connection successfully.
Here's the code that I use.

        final Object item = this.datasourceComboBox.getSelectedItem();
        if (item instanceof ConnectionWrapper) {
            final ConnectionWrapper cw = (ConnectionWrapper) item;
            this.selectedConnection = cw.getDatabaseConnection();
            
            ConnectionManager.getDefault().showConnectionDialog(this.selectedConnection);
            Connection jDBCConnection = this.selectedConnection.getJDBCConnection();
        }
Comment 4 Andrei Badea 2008-08-21 10:59:30 UTC
In which thread are you calling getJDBCConnection()?
Comment 5 Prashant Ponnala 2008-08-22 19:54:47 UTC
I have a JPanel which displays a comboBox with the list of connectionWrappers.
When the user selects one of the items, the actionPerformed(Event) calls the following method.

        final Object item = this.datasourceComboBox.getSelectedItem();
        if (item instanceof ConnectionWrapper) {
            final ConnectionWrapper cw = (ConnectionWrapper) item;
            this.selectedConnection = cw.getDatabaseConnection();
            
            ConnectionManager.getDefault().showConnectionDialog(this.selectedConnection);
            Connection jDBCConnection = this.selectedConnection.getJDBCConnection();
        }

Currently, the user has to select the comboBox item twice to get connected.
Comment 6 Andrei Badea 2008-08-22 20:50:45 UTC
So it is the event dispatching thread, that is good. So there may be a race condition somewhere. But before I go hunting
it, could you please try to reproduce the issue against the newest build of 6.5? I recall fixing a race condition in the
code called by getJDBCConnection() some time ago. Thanks.
Comment 7 David Vancouvering 2008-10-07 18:32:50 UTC
Have not heard from pponnala since August, assuming this is fixed.
Comment 8 Roman Mostyka 2008-10-08 10:43:54 UTC
v