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 76922 - Unable to connect to a database more than once with a type 2 driver
Summary: Unable to connect to a database more than once with a type 2 driver
Status: NEW
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 5.x
Hardware: PC Linux
: P4 blocker (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
: 72223 (view as bug list)
Depends on: 75204
Blocks:
  Show dependency tree
 
Reported: 2006-05-26 13:56 UTC by kovica
Modified: 2013-08-01 12:52 UTC (History)
3 users (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 kovica 2006-05-26 13:56:08 UTC
I'm using NetBeans 5.5 Dev (Build 200605251355) on Linux with java 1.5.0_06

When you use Generate entity beans from database wizard it creates a database
connection that you can see in Runtime - Databases. So go over it once so that
you get this connection. It doesn't matter if you generate classes or not. Just
get that conenction.

Steps to reproduce:
- go to Runtime - Databases and connect to the database the "Generate Entity
..." wizard is using
- use "Generate Entity ..." wizard and the tables are being read
- now cancel this using Cancel button
- disconnect from the database
- go to "Generate Entity ..." again and select the database conenction you
disconencted previously
- provide username and password and click OK
- I get the following Exception:
INFORMATIONAL *********** Exception occurred ************ at 2:54 PM on May 26, 2006
java.sql.SQLException: Unable to find a suitable driver
        at
org.netbeans.modules.db.explorer.DbDriverManager.createDriverNotFoundException(DbDriverManager.java:211)
        at
org.netbeans.modules.db.explorer.DbDriverManager.getDriverInternal(DbDriverManager.java:192)
        at
org.netbeans.modules.db.explorer.DbDriverManager.getConnection(DbDriverManager.java:80)
[catch] at
org.netbeans.modules.db.explorer.DatabaseConnection$2.run(DatabaseConnection.java:498)
        at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:493)
        at
org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:926)
Caused by: java.sql.SQLException: java.lang.UnsatisfiedLinkError: Native Library
/opt/IBM/db2/V8.1/lib/libdb2jdbc.so.1 already loaded in another classlo
        at COM.ibm.db2.jdbc.app.DB2Driver.<init>(Unknown Source)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:506)
        at java.lang.Class.newInstance0(Class.java:355)
        at java.lang.Class.newInstance(Class.java:308)
        at
org.netbeans.modules.db.explorer.DbDriverManager.getDriverInternal(DbDriverManager.java:190)
        ... 4 more


The problem is that I have to RESTART NetBeans if I want to generate more Entity
Classes.
Comment 1 Pavel Buzek 2006-06-08 16:31:57 UTC
Andrei, can you comment on this? Thanks.
Comment 2 Andrei Badea 2006-06-08 17:33:54 UTC
Caused by the fact that Database Explorer uses URLClassLoader's to load the JDBC
drivers. It creates a new URLClassLoader each time a connection is being made.
This causes the above problem with JDBC type 2 drivers, which need to load a
native library to communicate with the database. The native library can only be
loaded by a class loader, thus the exception.

The workaround is to use a JDBC type 4 driver.
Comment 3 kovica 2006-06-09 07:23:01 UTC
Using Type 4 driver is a solution, but you (abadea) yourself said if I can use
the app driver of the DB2, since the JCC driver is not working as it should.
Comment 4 Andrei Badea 2006-06-09 12:49:49 UTC
Sorry, I didn't know the app driver was a type 2 driver.
Comment 5 Andrei Badea 2006-06-15 16:55:43 UTC
Just changing the description to express the problem better.
Comment 6 Andrei Badea 2006-06-23 17:58:24 UTC
Need to somehow cache the URLClassLoader's instead of creating a new one on each
connection. Issue 75204 will probably have to be solved first for the caching to
be reliable.
Comment 7 Andrei Badea 2006-06-27 14:55:29 UTC
Caching the class loaders for JDBC drivers (at least until the driver's
properties are modified). Please verify.

Checking in ide/golden/deps.txt;
/cvs/ide/golden/deps.txt,v  <--  deps.txt
new revision: 1.175.2.4.2.93; previous revision: 1.175.2.4.2.92
done
Checking in db/nbproject/project.xml;
/cvs/db/nbproject/project.xml,v  <--  project.xml
new revision: 1.11.2.1.2.3; previous revision: 1.11.2.1.2.2
done
Checking in db/src/org/netbeans/modules/db/explorer/DbDriverManager.java;
/cvs/db/src/org/netbeans/modules/db/explorer/DbDriverManager.java,v  <-- 
DbDriverManager.java
new revision: 1.2.12.1.2.1; previous revision: 1.2.12.1
done
Checking in db/src/org/netbeans/modules/db/explorer/DbURLClassLoader.java;
/cvs/db/src/org/netbeans/modules/db/explorer/DbURLClassLoader.java,v  <-- 
DbURLClassLoader.java
new revision: 1.2.2.1.2.1; previous revision: 1.2.2.1
done
Checking in db/src/org/netbeans/modules/db/explorer/dlg/AddDriverDialog.java;
/cvs/db/src/org/netbeans/modules/db/explorer/dlg/AddDriverDialog.java,v  <-- 
AddDriverDialog.java
new revision: 1.33.2.1.2.1; previous revision: 1.33.2.1
done
RCS file: /cvs/db/test/unit/data/Attic/DummyDriver.class,v
done
Checking in db/test/unit/data/DummyDriver.class;
/cvs/db/test/unit/data/Attic/DummyDriver.class,v  <--  DummyDriver.class
new revision: 1.1.2.1; previous revision: 1.1
done
RCS file: /cvs/db/test/unit/data/Attic/DummyDriver.java,v
done
Checking in db/test/unit/data/DummyDriver.java;
/cvs/db/test/unit/data/Attic/DummyDriver.java,v  <--  DummyDriver.java
new revision: 1.1.2.1; previous revision: 1.1
done
Checking in
db/test/unit/src/org/netbeans/modules/db/explorer/DbDriverManagerTest.java;
/cvs/db/test/unit/src/org/netbeans/modules/db/explorer/DbDriverManagerTest.java,v
 <--  DbDriverManagerTest.java
new revision: 1.4.6.1.2.1; previous revision: 1.4.6.1
done
Comment 8 Andrei Badea 2006-06-27 14:57:22 UTC
The error can still be experienced, e.g. when the user connects with a driver,
modifies the driver's properties and tries to reconnected. But the user impact
is mitigated, so downgrading. 

Gregor, please verify that you don't get the exception anymore.
Comment 9 kovica 2006-06-28 11:44:23 UTC
I can verify that I don't get an Exception anymore. Good work :)
Comment 10 Andrei Badea 2006-06-30 19:01:14 UTC
*** Issue 72223 has been marked as a duplicate of this issue. ***
Comment 11 David Vancouvering 2008-01-17 04:25:27 UTC
Hi, Andrei.  Why did you re=open this.  It looks like the last comment was that your fix was verified.  Can you please
provide more details.
Comment 12 Andrei Badea 2008-01-21 14:11:22 UTC
Because the right fix for this is to clean up when disconnecting, so that the driver's class loader can be
garbage-collected. Currently it can't be, for example because the driver is registered in DriverManager.
Comment 13 Jiri Rechtacek 2009-07-01 07:58:02 UTC
Reassigned to new owner.