netbeans icon indicating copy to clipboard operation
netbeans copied to clipboard

Java DB drivers are not referencing correct Derby classes

Open DiskCrasher opened this issue 2 years ago • 7 comments

Apache NetBeans version

Apache NetBeans 17

What happened

The default Java DB drivers shown under NetBeans Services window point to incorrect/outdated Derby classes resulting in ClassNotFound exceptions when attempting to use them. The correct classes are:

org.apache.derby.jdbc.EmbeddedDriver - for Java DB (Embedded) located in derbytools.jar org.apache.derby.client.ClientAutoloadedDriver - for Java DB (Network) located in derbyclient.jar

Additionally, even after the drivers are updated to point to these new classes, attempting to create a new database results in a ClassNotFound exception for org.apache.derby.jdbc.ClientDriver. It doesn't appear to be using the modified driver settings. Even the "sample" database throws a "The Java DB (Network) driver was not found" error upon connect which doesn't make sense since that driver exists.

How to reproduce

Install the default Derby DB in NetBeans 17 and attempt to use the provided Java DB drivers or connect to the "sample" database.

Did this work correctly in an earlier version?

No / Don't know

Operating System

Windows 11

JDK

Microsoft build of OpenJDK with Hotspot 17.0.6+10 (x64)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

Yes

DiskCrasher avatar Mar 18 '23 02:03 DiskCrasher

It looks like that the driver classes were moved to a new JAR lib/derbytools.jar. This JAR needs to be added to both Java DB Network and Embedded configurations.

A workaround is to add this JAR manually to the existing configurations. There's no workaround for fixing the problem when when creating a new DB - the only workaround is to copy the content of lib/derbytools.jar into the lib/derbyclient.jar.

I think that to fix this in Netbeans, the lib/derbytools.ar needs to be added in these 2 places:

  • https://github.com/apache/netbeans/blob/711207c11ba278c94b05d931ebd5fdc3a4b55d9f/ide/derby/src/org/netbeans/modules/derby/DerbyOptions.java#L253 - to register the drivers with this additional JAR
  • https://github.com/apache/netbeans/blob/711207c11ba278c94b05d931ebd5fdc3a4b55d9f/ide/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java#L545 - to add this additional JAR to the DbURLClassLoader to load the driver class. This is used during creation of a new DB

I'm willing to submit a pull request when I have some time, but I won't be able to get to this in the following weeks. @DiskCrasher , if you'd like to submit a PR, go for it. I hope that with my advice, it should be pretty straightforward to fix this.

OndroMih avatar May 28 '23 12:05 OndroMih

I took a quick look at the code and changed both DRIVER_PATH_NET and DRIVER_PATH_EMBEDDED to point to lib\derbytools.jar. I also modified line 548 to reflect the same. This did not resolve the problem as I'm now getting an "unable to find suitable driver" error for org.apache.derby.jdbc.ClientDriver on connection attempt. In doing some searching I found other classes that reference the old jar files so they may need to change as well?

DiskCrasher avatar May 30 '23 03:05 DiskCrasher

It's not enough to replace derbyclient.jar with derbytools.jar. Both of them are required. So you need to add derbytools.jar but also keep the derbyclient.jar.

OndroMih avatar May 30 '23 19:05 OndroMih

I gave it another shot by adding derbytools.jar to both methods but still no success. When I look under Database/Drivers/Java DB and hit Customize it's not showing derbytools.jar listed under Driver Files. Manually adding it seems to work. I'm not familiar with this code (or Derby for that matter) so I'm probably missing something.

DiskCrasher avatar May 31 '23 03:05 DiskCrasher

Did this ever get resolved? I can open the sample app database, but I can't create my own database. Pls help, sincerely, very confused new java student.

StephenBuley avatar Jun 03 '24 10:06 StephenBuley

I know exactly what is the issue and how to solve it. I just haven't had enough time to do it. A quick and dirty fix is to open the derbytools.jar file in the Derby DB installation as a ZIP file, and copy all the files from it into the derbyclient.jar.

OndroMih avatar Jun 03 '24 13:06 OndroMih

Found a work around that will work for my class, but thank you!

StephenBuley avatar Jun 03 '24 13:06 StephenBuley