B4J Question B4JPackager11 JTDS Charset Issue

Status
Not open for further replies.

Philip Chatzigeorgiadis

Active Member
Licensed User
I have a small UI app connected to SQLServer database, which runs fine from the the B4J IDE.
After packing it with B4JPackager 11, I got this error:
B4X:
D:\ALLDOCS\JAVAPROGRAMS\B4JPackager11\Objects\temp\build\bin>java.exe @release_java_modules.txt  -m b4j/b4j.example.main
main._appstart (java line: -1)
java.sql.SQLException: Could not find a Java charset equivalent to DB charset Cp1252.
        at b4j/net.sourceforge.jtds.jdbc.JtdsConnection.loadCharset(Unknown Source)
        at b4j/net.sourceforge.jtds.jdbc.JtdsConnection.<init>(Unknown Source)
        at b4j/net.sourceforge.jtds.jdbc.Driver.connect(Unknown Source)
        at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.SQL.Initialize2(Unknown Source)
        at b4j/anywheresoftware.b4j.objects.SQL.Initialize(Unknown Source)
        at b4j/b4j.example.main._appstart(Unknown Source)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent2(Unknown Source)
        at b4j/anywheresoftware.b4a.BA.raiseEvent(Unknown Source)
        at b4j/b4j.example.main.start(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(Unknown Source)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

Following the suggestion for a similar problem here:


I replaced the JTDS (jtds-1.3.1.jar) driver with MSSQL JDBC driver (mssql-jdbc-8.2.2.jre11.jar) and the problem was fixed.

Is there another solution or workaround, so that I can keep using the JTDS driver?
 

Philip Chatzigeorgiadis

Active Member
Licensed User
Try to set the charset in the connection string.
Add charset=utf8
Tried these combinations in the connection string:
charset=utf8, got error: java.sql.SQLException: Could not find a Java charset equivalent to DB charset utf8.
charset=UTF8, got error: java.sql.SQLException: Could not find a Java charset equivalent to DB charset UTF8.
charset=utf-8, got error: java.sql.SQLException: Could not find a Java charset equivalent to DB charset utf-8.
charset=UTF-8, got error: java.sql.SQLException: Could not find a Java charset equivalent to DB charset UTF-8.

In all caseS the App ran fine in the IDE.
 
Upvote 0

Philip Chatzigeorgiadis

Active Member
Licensed User
Do you get the exact same error? Try to put the net folder inside the parent folder.
The error on the MAC was the same: java.sql.SQLException: Could not find a Java charset equivalent to DB charset UTF8
UTF8 was set in the connection string.
The error remained the same even when I copied the net folder inside the parent folder (so net was present both in the parent and in the bin folder).

However, I had a setback today.
When I tried to go back to windows and do further testing, the error (java.sql.SQLException: Could not find a Java charset equivalent to DB charset UTF8 ) appeared again, although yesterday afternoon it tested OK.
I made sure that I used the exact same configuration as yesterday afternoon (used a backup copy I took immediately after the succesful run) but the error persists.
(Starting to doubt my sanity ...)
 
Upvote 0

netsistemas

Active Member
Licensed User
All perfect, thanks. I complete the message with this words
Remember, THIS IS FOR B4J (no b4a)

Change this in main.

' #AdditionalJar: jtds-1.3.1.jar

#AdditionalJar: mssql-jdbc-8.4.1.jre11

Download last library from:

And use this connection:

B4X:
        CC = $"jdbc:sqlserver:${ServerConfig.Server};user=${ServerConfig.Usu};integratedSecurity=false;password=${ServerConfig.clave};databaseName=${ServerConfig.DB};"$

        SqlServer.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver", CC)
 
Last edited:
Upvote 0

Johan Schoeman

Expert
Licensed User
Is there any solution for.....
B4X:
java.sql.SQLException: Could not find a Java charset equivalent to DB charset Cp1252
.....when making use of #AdditionalJar: jtds-1.3.1 and compiling the B4J project to a standalone package?

Running the B4J app from the IDE is working perfectly but cannot get the standalone exe to run
Have tried adding various charset's to the Initialize string but it always fails - tried UTF-8, ISO-8859-1, Cp1252

eg:
B4X:
    SQL1.Initialize("net.sourceforge.jtds.jdbc.Driver","jdbc:jtds:sqlserver://xx.x.xxx.xx:1433/Syspro_Live_xxx_x;integratedSecurity=true;useNTLMv2=true;charset=UTF-8;")

Have searched the forum but cannot find a solution. Really don't want to switch to a Microsoft driver
 
Upvote 0
Status
Not open for further replies.
Top