Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError sun/io/ByteToCharConverter with InterBase JDBC driver

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

like image 729
mjn Avatar asked Aug 18 '14 14:08

mjn


5 Answers

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.

like image 179
Vinod Kotha Avatar answered Oct 02 '22 19:10

Vinod Kotha


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.

like image 20
Kayaman Avatar answered Oct 02 '22 20:10

Kayaman


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

like image 44
alizelzele Avatar answered Oct 02 '22 20:10

alizelzele


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.

like image 36
mjn Avatar answered Oct 02 '22 20:10

mjn


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.

like image 24
Androclus Avatar answered Oct 02 '22 20:10

Androclus