java - How to enter a relative URL when linking to an access database -


i'm doing java project school have use ms access store data. i've managed database , running, can't seem find how make link database relative. i've searched web , tried can think of nothing seems work. here can help?

here's how i've put link now:

private static final string database_url = "jdbc:odbc:driver={microsoft access driver (*.mdb, *.accdb)};dbq=c:\\users\\badlapje\\dropbox\\workspace\\foop\\group62risk\\risk.accdb"; 

which invoke follows:

connection = drivermanager.getconnection(database_url); 

what want make link relative, members of our team can use same link.

the problem in access database file location: c:\\users\\badlapje\\dropbox\\workspace\\foop\\group62risk\\risk.accdb. make sure place file in folder has in computer c:\\school-project\\risk.accdb.

another solution set file inside java project inside source package , load file absolute path using java code (adapted this answer):

package edu.proj.res;  public class main {     public static string getdatabaselocation() {         return main.class.getclassloader().getresource("edu/proj/res/database.txt").tostring();     }     public static string changetowindowspath(string path) {     return path.replace("file:/", "").replaceall("/", "\\\\"); }     public static void main(string[] args) {         system.out.println(changetowindowspath(getdatabaselocation()));     } } 

having project structure:

consoletests - src   - edu.proj.res     + database.txt     + main.java 

program output:

c:\workspace\consoletests\bin\edu\proj\res\database.txt 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -