I suggest this code should obtain an URL to the DB..
// important to put the leading '/'!
URL theDB = anObject.getClass().
getResource("/Data/Database/MyDataBase.mdb")
Tx alot, it works for getting the ressource. Thus I have another problem to
run the jar.
URL theDB = this.getClass().getResource("/Data/Database/MyDatabase.mdb");
String g = theDB.getPath();
String myDB = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ= " +
g.substring(1);
conn = DriverManager.getConnection(myDB," ", " ");
When I run it form my IDE it works. But when running the jar (lets' suppose
the jar is in c:\) I get the following error.
C:\>java -jar ProLamp_fat.jar
file:/C:/ProLamp_fat.jar!/Data/Database/MyDatabase.mdb
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Not a valid
fil
e name.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at database.BD.OpenDB(BD.java:47)
...
Maybe its a problem with the manifest ? Here's mine :
is, the data cannot reside inside the JAR. They need to reside in the file
system.
file, but that's the same for purposes of discourse). You'd constantly
rewrite the compressed file with every change to the database contents. Not
feasible. The JAR format isn't made for that.
You need the database to reside in an accessible file system.