B4J Question B4j Connect Access MDB file

Jones Hone

Active Member
Licensed User
Longtime User
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
    #AdditionalJar: ucanaccess-4.0.4.jar
    #AdditionalJar: hsqldb.jar
    #AdditionalJar: jackcess-2.1.11.jar
    #AdditionalJar: commons-logging-1.1.3.jar
    #AdditionalJar: commons-lang-2.6.jar
#End Region

Sub Process_Globals
    Private gSQL As SQL
    Private DBFile As String
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("test")
    MainForm.Show
    '
    DBFile = File.DirApp & "\B4JTEST1.MDB"
    Try
        gSQL.Initialize("net.ucanaccess.jdbc.UcanaccessDriver", "jdbc:ucanaccess://" & DBFile & ";memory=true")
        Dim Cursor As ResultSet
        Cursor = gSQL.ExecQuery("SELECT * from PLU")
        Do While Cursor.NextRow
            Log(Cursor.GetString("PLUNO") & "." & Cursor.GetString("PNAME"))
        Loop
    Catch
        Log(LastException.Message)
    End Try
End Sub

If there is a table named PLU(only 10 records.) in b4jtest1.mdb.
It only takes 2 seconds to execute the above program.

But. If there is a table named PLU(only 10 records) and HIST table(have 100,000 records) in b4jtest1.mdb
It need takes 40 seconds to execute the above program.

Why do I just read the PLU table, if there are other tables in the database, it will slow down?
Is there a solution?
Thank you!
 

Jones Hone

Active Member
Licensed User
Longtime User
The database is being used by the existing program, and conversion to other databases is not allowed.
gSQL.Initialize(): This command took too much time.
Switch to gSQL.InitializeAsync() always slow.
 
Upvote 0

Jones Hone

Active Member
Licensed User
Longtime User
I found. When the program is running will auto generate Ucanaccess_net.ucanaccess.jdbc.DBReference@10c2bb3 this temporary directory.
The directory size bigger than the b4jtest1.mdb database(Now the database size is 205MB).

It should be to create this temporary directory, so it took so much time.
Can let it not create a temporary directory?
 
Upvote 0

BigBoss123

Member
Licensed User
Longtime User
Just noticed you still have an old *mdb using Jet engine 4.
Can you not update to the new Jet engine 12 and use *.accdb.

Cheers
 
Upvote 0

Jorge M A

Well-Known Member
Licensed User
Longtime User
UCanAccess uses an HSQLDB "mirror database" which by default is stored in memory and must be recreated when the application opens the Access database. That involves copying the data from the Access tables into HSQLDB tables, which can take some time if the Access database is large. Having the Access database on a network share will further slow that process.
If the Access database is unlikely to change very often between the times that you launch your Java app then you could use the UCanAccess keepMirror connection parameter to persist the mirror database in a folder on your local hard drive. That would reduce your application startup time because UCanAccess would not have to rebuild the mirror database each time.
See the UCanAccess site for details.

Source: https://stackoverflow.com/questions/31991838/slow-initial-connection-to-ms-access-database
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Besides the mirror database, you may want to try not setting memory=false and try to increase the JVM heap space

Links:

 
Upvote 0

Jones Hone

Active Member
Licensed User
Longtime User
@BigBoss123:
The database is being used by an existing program and cannot be replaced with .accdb

@Jorge MA:
I have tried "keepMirror", But, That database is updated at any time. So it will always rebuild the mirror. So it still took a lot of time.

@OliverA:
I have tried memory=false, But it's always out of memory! Because my database may be nearly 1G MB in size.

It seems that I may have to give up using UCANACCESS.
Excuse me, is there any other library available?
 
Upvote 0
Top