java - Access H2 Database from application contained in a JAR File -
java - Access H2 Database from application contained in a JAR File -
i have application uses h2 database , next connection string:
connection connection = drivermanager.getconnection("jdbc:h2:file:data/sample", "sa", "");
it works quite under eclipse, if bundle java desktop application in jar file, cannot find h2 database in data/sample more. here running directory:
application.jar info | sample.h2.db
and here how seek execute application:
java -classpath .; -jar application.jar
a sqlexception raised no tables found. hint how have connection running eclipse , within jar file ? please note requirement should not utilize absolute path database relative path, because database folders unzipped along jar files application installer.
there possible causes of error can think :
the database empty. might have populate when building application under eclipse when launching jar file, nail empty 1 : command using h2 console, , either populate database @ launch time if empty or set initialized 1 along jar. as give relative path database, actual path depends on current working directory. rather unusual , error prone. you'd improve give absolute path, found in environment variable or in java scheme property : it's still configurable more explicitfor sec possibility, h2 automatically creates new database if not find it. avoid automatic creation when path wrong, can add together ;ifexists=true
url : "jdbc:h2:file:data/sample;ifexists=true"
. avoid relative paths if can ...
java h2
Comments
Post a Comment