How to set MS Access database path in UCanAccess?

1.8k views Asked by At

This is my current database path

"jdbc:ucanaccess://D:/Java/TransactionProcessingSystem/src/transactionprocessingsystem/Resources/TPSystem.accdb"

But I want set the database path in the same compilation folder location, Like this:

"jdbc:ucanaccess://../Resources/TPSystem.accdb"

I am using Netbeans to develop the program.

2

There are 2 answers

0
jamadei On

It just must be a valid path(relative or absolute). Therefore, if you're using a relative path, it must be relative to the current working directory.

0
Rohith Chandupatla On

You have to use ClassLoader class. Firstly put the resource file(TPSystem.accdb) in src/main/resource of your maven project.

ClassLoader classLoader = getClass().getClassLoader();
File file = new 
File(classLoader.getResource("TPSystem.accdb").getFile());

and now the file Path will be

String filePath = "jdbc:ucanaccess://"+file.getAbsolutePath();