Initial conditions: a DBMS instance with multiple databases (I'm using SQL server). I'll call the databases "db1" and "db2".
1. In Netbeans, add a DB connection for the DBMS. Specifify "db1" as the database to connect to.
2. Connect to the DBMS through netbeans.
3. Open the node for the DBMS, then navigate to db2-->dbo-->Tables.
4! Right-click on Tables and select "Execute Command..." from the context menu. The SQL CC shows completions for db1 instead of db2 as expected, and the active DB when running the query is set to db1.
To summarize, if the user picks a node under db2 and opens an SQL query window, she expects the active DB to be db2, even if the connection was created using db1 as the default. Due to this and also issue #200368, there's no way to get CC for db2 without explicitly creating a connection for it.