8

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

mjn
  • 35,561
  • 24
  • 160
  • 351
  • 1
    Do you include these libraries in your deployment or are they a separate module? The `sun.jdk` module contains the `sun/io` paths. – James R. Perkins Aug 19 '14 at 14:48
  • What version of sql jdbc jar you are using? – Nivetha T Jan 28 '15 at 13:09
  • @NivethaT tried with InterClient versions 7.5.1 and 8.1.5. Do you suggest that we should try a newer InterClient version? – mjn Jan 28 '15 at 15:01
  • 1
    @mjn You're saying that you haven't even tried the latest version of the driver? That would've been the first thing to try. – Kayaman Jan 29 '15 at 07:14
  • Related: [interbase.interclient.UnlicensedComponentException with the latest interclient.jar IB (v7.5.80)](http://stackoverflow.com/questions/28050976/), 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) – mjn Feb 19 '15 at 14:09
  • @Kayaman 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 :) – mjn Feb 19 '15 at 14:26

7 Answers7

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.

Jonathan Hult
  • 1,116
  • 2
  • 11
  • 16
Kayaman
  • 67,952
  • 3
  • 69
  • 110
  • 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. – mjn Feb 19 '15 at 14:25
  • 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 :) – Kayaman Feb 20 '15 at 08:34
  • Link seems to be broken . – Akhil Nambiar Aug 10 '17 at 08:10
6

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.

frianH
  • 5,901
  • 6
  • 13
  • 36
Vinod Kotha
  • 97
  • 1
  • 2
2

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

alizelzele
  • 805
  • 18
  • 34
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.

Community
  • 1
  • 1
mjn
  • 35,561
  • 24
  • 160
  • 351
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.

androclus
  • 191
  • 1
  • 4
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.

Sergio
  • 9
  • 2
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