B4J Question Build Standalone Package issues when working with local databases:

vmag

Active Member
1. Real File.DirApp = File. DirApp & "\bin" in the build folder, not next to the executable *. exe file (located not nearby), the entire meaning of the File.DirApp operator is lost (make no sense).
2. Final Assembly Build from the Standalone Package does not work with local database Access (in this instance):
B4X:
#Region Project Attributes
#MainFormWidth: 1024
#MainFormHeight: 768
#AdditionalJar: ucanaccess-5.0.0.jar
#AdditionalJar: hsqldb-2.5.0.jar
#AdditionalJar: jackcess-3.0.1.jar
#AdditionalJar: commons-logging-1.2.jar
#AdditionalJar: commons-lang3-3.8.1.jar
#End Region
-Version B4J - 8.30
- Java-jdk-14.0.1
-All materials for working with the database are taken from this site
Problems with the jackcess library already at the DB creation stage (the file is created but it is empty and not marked up for the DB):
B4X:
D:\build\bin>java.exe @release_java_modules.txt -m b4j/b4j.example.main
java.io.IOException: Could not load jackcess resource com/healthmarketscience/jackcess/empty.mdb
java.lang.RuntimeException: Object should first be initialized.
java.lang.RuntimeException: Object should first be initialized.
..............................................................
Before Build Standalone Package everything works without any comments here is the result in Release mode
 

vmag

Active Member
1. Even so, I changed the path to an existing folder C:\DB (didn't help).
2. Here is the code:
B4X:
#Region Project Attributes
    #AdditionalJar: ucanaccess-5.0.0.jar
    #AdditionalJar: hsqldb-2.5.0.jar
    #AdditionalJar: jackcess-3.0.1.jar
    #AdditionalJar: commons-logging-1.2.jar
    #AdditionalJar: commons-lang3-3.8.1.jar
#End Region

Sub Process_Globals
    Private fx As JFX
    Public DBFile As String
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    'DBFile = File.DirApp & "\" & "money.mdb"
    DBFile = "C:\DB\db.mdb"
    If CreateDba(DBFile, False, "V2000", True, False, True)=False Then
        fx.Msgbox(Form1, "Error create bd!", "Problems !")
        Else
        fx.Msgbox(Form1, "Bd created!", "Great !")
    End If
    Form1.Close
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Public Sub CreateDba(DBFile_ As String, Pmemory As Boolean, PnewDatabaseVersion As String, PshowSchema As Boolean, PopenExclusive As Boolean, PpreventReloading As Boolean) As Boolean
    'DBFile - the path to the database *.mdb (расположение файла *.mdb)
    'True/False - its backing database only in memory (резервная копия БД только в памяти)
    ' Format BD (V2000, V2003, V2007, V2010) (формат новой БД)
    'True/False - showSchema (схема БД)
    'True/False - openExclusive (монопольный доступ)
    'True/False - preventReloading (оптимизация при работе совместно с другими интерфейсами)
    Log("Database file: " & DBFile)
    Dim Result As Boolean
    Dim ConDba_ As SQL
    Try
        Log(" Init sql connection...")
        ConDba_.Initialize("net.ucanaccess.jdbc.UcanaccessDriver", "jdbc:ucanaccess://" & DBFile & _
        ";memory=" & Pmemory & ";newDatabaseVersion=" & PnewDatabaseVersion & ";showSchema=" & PshowSchema & ";openExclusive=" & PopenExclusive & ";preventReloading=" & PopenExclusive)
        Result = True
    Catch
        Log(LastException.Message)
        Result = False
    End Try
    Return Result
End Sub
Libraries: jCore, jFX, jSQL
other libraries - from this site
Everything works in Release and Debug modes (you need to create a folder first C:\DB):
- if there is no db.mdb file, it is created correctly
- if it is already there, then there is a connect
After the Build of from the Standalone Package error:
- if there is no file, it is not created working (size 0 bytes):
java.io.IOException: Could not load jackcess resource com/healthmarketscience/jackcess/empty.mdb
-
if you put a working database file in the folder, connect error:
java.lang.ExceptionInInitializerError
at b4j/com.healthmarketscience.jackcess.impl.GeneralLegacyIndexCodes.getCharHandler(Unknown Source)
at b4j/com.healthmarketscience.jackcess.impl.GeneralLegacyIndexCodes.writeNonNullIndexTextValue(Unknown Source)
at b4j/com.healthmarketscience.jackcess.impl.IndexData$GenLegTextColumnDescriptor.writeNonNullValue(Unknown Source
........................................................ bla bla bla...............
 
Upvote 0

vmag

Active Member
Dear Erel, Your example from the lessons for SQLite, unfortunately after Build Standalone Package does not work either:
B4X:
#AdditionalJar: sqlite-jdbc-3.7.2.jar
B4j 8.30
Java-jdk-14.0.1

Log:
C:\B4J_SQL\Objects\temp\build>cd bin

C:\B4J_SQL\Objects\temp\build\bin>java.exe @release_java_modules.txt -m b4j/b4j.example.main
main._process_globals (java line: -1)
java.lang.NoClassDefFoundError: javafx/scene/web/WebView
at b4j/anywheresoftware.b4j.objects.WebViewWrapper.<clinit>(Unknown Source)
at b4j/b4j.example.main._process_globals(Unknown Source)
at b4j/b4j.example.main.initializeProcessGlobals(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(Unknown Source)
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)
Caused by: java.lang.ClassNotFoundException: javafx.scene.web.WebView
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 13 more


Works in Release and Debug modes - normal end no problems...
 
Upvote 0

vmag

Active Member
Yes Erel, a simple replacement of jackcess-3.0.1 with jackcess-3.0.1-B4J solved all the problems, thank you for your quick response to the problem! The last question on this topic - is will this
B4X:
    #AdditionalJar: ucanaccess-5.0.0.jar
    #AdditionalJar: hsqldb-2.5.0.jar
    #AdditionalJar: jackcess-3.0.1-B4J
    #AdditionalJar: commons-logging-1.2.jar
    #AdditionalJar: commons-lang3-3.8.1.jar
work in B4A ( jackcess-3.0.1-B4J)?
 
Upvote 0

vmag

Active Member
Erel, I tested this question in more detail and here is the final result:
1. Now you can work with existing Access databases (2000-2010) in all modes, including Package, without problems.
2. The problem is only with creating new databases in Package mode, empty database templates are not available (empty2000. mdb, empty2003.mdb,empty2007.accdb, empty2010.accdb) this causes the following error:
java.io.IOException: Could not load jackcess resource com/healthmarketscience/jackcess/empty2007.accdb
If you use the database creation string instead of the connection string in your example,
B4X:
sql = DbaUtils.CreateDba("C:/Users/H/Downloads/1.accdb", True, "V2007", True, False, True)
you will get this error
Of course, before starting the project, delete the file 1.accdb, otherwise, instead of creating the file, you will connect to the existing file and the error will not occur
 
Upvote 0
Top