NoClassDefFoundError sun/io/ByteToCharConverter with InterBase JDBC driver
Asked Answered
K

7

9

With InterClient 7.5.1 and 8.1.5, the creation of a new JDBC connection in Java 8 fails with

java.lang.NoClassDefFoundError: sun/io/ByteToCharConverter

This class seems to be referenced or used by the InterClient JDBC library. The error does not occur with Java 7. Is there a way to work around this error?


This code reproduces the problem on Java 8:

package com.example.so25365952;

import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Main {
    interbase.interclient.Connection conn; 

    public static void main(String[] args) {
        try {
            Class.forName("interbase.interclient.Driver");           
            DriverManager.getConnection("jdbc:interbase://localhost/data/mydb.gdb", "sysdba", "password123");           
        } catch (ClassNotFoundException | SQLException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

Output:

Exception in thread "main" java.lang.NoClassDefFoundError: sun/io/ByteToCharConverter at interbase.interclient.Connection.connect(Unknown Source) at interbase.interclient.Connection.(Unknown Source) at interbase.interclient.Driver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.example.so25365952.Main.main(Main.java:14) Caused by: java.lang.ClassNotFoundException: sun.io.ByteToCharConverter at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 6 more

Koeninger answered 18/8, 2014 at 14:38 Comment(6)
Do you include these libraries in your deployment or are they a separate module? The sun.jdk module contains the sun/io paths.Moneyer
What version of sql jdbc jar you are using?Haplology
@NivethaT tried with InterClient versions 7.5.1 and 8.1.5. Do you suggest that we should try a newer InterClient version?Koeninger
@Koeninger You're saying that you haven't even tried the latest version of the driver? That would've been the first thing to try.Witt
Related: interbase.interclient.UnlicensedComponentException with the latest interclient.jar IB (v7.5.80), I verified that our InterBase 7.5.1 will cause this client side exception with the most current version of the InterBase JDBC driver (XE7)Koeninger
@Witt the latest version has a different problem: it refuses to connect to old server versions. I did not try it earlier because I suspected something like this would happen :)Koeninger
W
6

The sun.* and sunw.* packages are internal and should not be used for exactly this reason. Seems like someone at InterClient screwed up. I'd advise you to contact them with a bug report, so they'll know to fix this for future releases.

If you can't wait for a future release, and are willing to break some licences (which I don't recommend of course). You may be able to create your own sun.io.ByteToCharConverter by copying the code from here, and adding it to the bootstrap classpath with -Xbootclasspath, but that would be a last resort.

Witt answered 18/8, 2014 at 15:14 Comment(3)
I tried to extract the sun.io classes and add it as a separate jar to the project. It works, but feels a bit like hacking around.Koeninger
Well it's certainly hacking around. Unfortunately you have very little choice until you update your database to a later version and driver...but at least it works :)Witt
Link seems to be broken .Melina
B
7

Use db2jcc4.jar which is latest version. If you changed your mind to use Java 8 you need to use this.

I have the similiar problem and this change help me to fix the error.

Beckman answered 19/4, 2017 at 17:3 Comment(2)
How does using a DB2 driver solve a problem for connecting to Interbase?Bankable
@MarkRotteveel The issue is also common for db2 connections. However, these questions are closed as the duplicate of this question.Tagmemic
W
6

The sun.* and sunw.* packages are internal and should not be used for exactly this reason. Seems like someone at InterClient screwed up. I'd advise you to contact them with a bug report, so they'll know to fix this for future releases.

If you can't wait for a future release, and are willing to break some licences (which I don't recommend of course). You may be able to create your own sun.io.ByteToCharConverter by copying the code from here, and adding it to the bootstrap classpath with -Xbootclasspath, but that would be a last resort.

Witt answered 18/8, 2014 at 15:14 Comment(3)
I tried to extract the sun.io classes and add it as a separate jar to the project. It works, but feels a bit like hacking around.Koeninger
Well it's certainly hacking around. Unfortunately you have very little choice until you update your database to a later version and driver...but at least it works :)Witt
Link seems to be broken .Melina
N
4

sun.io.ByteToCharConvertor was deprecated in java 7. and it seems they remove it in java 8.

Nativeborn answered 26/1, 2015 at 13:13 Comment(1)
Citation please. As it wasn't even documented in Java 7 how could it have been deprecated?Petrography
K
1

The answer to the question interbase.interclient.UnlicensedComponentException with the latest interclient.jar IB (v7.5.80) seems to work for me too. It suggests to use version 1.5 of the JDBC driver for Firebird. Fortunately this driver does not rely on deprecated sun classes and works with JRE 8.

Koeninger answered 19/2, 2015 at 14:24 Comment(0)
B
1

I agree with Sergio, this is now an even older question! :-) But at my workplace, too, we are unfortunately as of 2018 for various reasons still using a super-old Interbase (v9, 2009). So at some point I too was unable to continue using the interclient.jar packaged with IBv9, because I would receive this same sun.io.ByteToCharConverter error. No doubt this was because the Java on my client machine was so much newer now. After all, it is 9 years later. But I did not want in my case to go with the solution of installing a legacy Java on my machine, as has worked for others.

So as a solution, on my client machine (Linux/Debian x64), I installed Interbase 2017, the latest at the time(*). But when installing, I only installed the IB Client (not Server + Client). The /opt/interbase/lib/interclient.jar that is packaged with the IB 2017 client works just fine now (no sun.io error). And yes, this IB 2017 (v13) interclient.jar works just fine connecting to our old IB 2009 server.

(I have to hand it to Embarcadero: They are still 'supporting' being able to connect to older versions -- at least in their interclient.jar and libgds.so. This makes sense as useful of course for those sysadmins who want to migrate from older systems to newer ones.)

(*) You can get a free trial version of Interbase from embarcadero. As far as I can tell, though, when you install it, if you install the Client only and use the interclient.jar, this does not require a license. Only installing the IB server (and depending on number of users/connections, etc) but that is nothing new to IB users/admins.

Works for us, at least, until we upgrade our server's IB version, or move to Firebird.

Hope this helps at least one other person out there.

Bartholomeus answered 10/9, 2018 at 19:43 Comment(0)
V
0

This is an old question, but in case this helps someone:

Find the Java 7 rt.jar in the lib folder. Open the file, and go to the folder sun/io.

Find the Java 8 rt.jar in the lib folder. Open the file, and go to the folder sun/io.

Move all the .class files in the folder sun/io from the Java 7 to the Java 8 sun/io folder, except for Win32ErrorMode.class (this class was in both jar files).

Save the Java 8 rt.jar with the added classes.

This worked for me, using an old jdbc driver for SQL Server.

Vanvanadate answered 1/5, 2018 at 19:16 Comment(1)
Butchering the installed JDK/JRE cannot be recommended.Petrography
S
0

use

<!-- https://mvnrepository.com/artifact/com.ibm.db2.jcc/db2jcc -->
        <dependency>
            <groupId>com.ibm.db2.jcc</groupId>
            <artifactId>db2jcc</artifactId>
            <version>db2jcc4</version>
        </dependency>

replace

<dependency>
            <groupId>com.ibm.db2.jcc</groupId>
            <artifactId>db2jcc</artifactId>
            <version>10.1</version>
        </dependency>

can Solve the problem

Steelwork answered 14/11, 2019 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.