I have a local MS Access database, and I'm trying to connect to it via Java. I'm using UCanAccess as the JDBC driver, and while the database is linked to a password protected database on a network drive, the one I'm connecting to has already been authenticated, and is not password protected itself. I have all of the dependencies in my classpath. When connecting, I keep getting this error:
java.lang.OutOfMemoryError: Java heap
I fired up Java VisualVM, and indeed, the main thread is eating up all 2GB of allocated memory. This has only ever happened to me when I tried to select a massive number of records from a large MySQL Database. I can't find any results on Google that relate to this happening upon connection, as I'm not even attempting to query the DB.
The code is simply:
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.out.println("Initiating connection...");
conn = DriverManager.getConnection("jdbc:ucanaccess://C:/Databases/StoreSalesCurrent.accdb");
System.out.println("Connection established");
conn.close();
Any idea why just trying to establish a connection would cause such large memory consumption?
By default UCanAccess loads the entire database into memory at the very first connection in the life of the JVM. This was chosen as the default behavior because the typical usage case is for smaller personal databases, not ones that are gigabytes in size.
It will work with the proper connection parameters, e.g., setting memory=false
and perhaps other related options, but the startup time (the time of the very first connection in the JVM life) may become high. See the UCanAccess website for more details.