Warm tip: This article is reproduced from stackoverflow.com, please click
java java-8 jdbc interbase

NoClassDefFoundError sun/io/ByteToCharConverter with InterBase JDBC driver

发布于 2020-04-11 11:58:24

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

Questioner
mjn
Viewed
103
1,031 2019-04-25 13:01

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.