ex3v
ex3v

Reputation: 3566

Hibernate + SQLite db outside jar

After few years of PHP I decided to learn Java, so I'm writing simple desktop app that uses Hibernate and SQLite.

I'd like to keep database outside of the .jar generated by mvn package, so one can perform quick backup of the data just by copying one file. So far, my hibernate.cfg.xml looks like this:

<hibernate-configuration>
    <session-factory>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <property name="dialect">org.hibernate.dialect.SQLiteDialect</property>
        <property name="connection.driver_class">org.sqlite.JDBC</property>
        <property name="connection.url">jdbc:sqlite:mydb.db</property>
        <property name="connection.username"></property>
        <property name="connection.password"></property>

        <property name="hibernate.hbm2ddl.auto">update</property>

        <mapping class="com.ex3v.hibernate.Contact"/>
    </session-factory>
</hibernate-configuration>

what connection.url do I have to specify to make hibernate create db file next to .jar in working directory?

Upvotes: 0

Views: 9504

Answers (2)

roushan kumar Singh
roushan kumar Singh

Reputation: 384

Use relative path like this. jdbc:sqlite:./DB/mydb.db

Upvotes: 1

nIx..
nIx..

Reputation: 370

You can find your answer here:

Just a summary from above site, different formats are :

  • jdbc:sqlite:mydb.db
  • jdbc:sqlite://dirA/dirB/mydb.db
  • jdbc:sqlite:/DRIVE:/dirA/dirB/mydb.db
  • jdbc:sqlite:///COMPUTERNAME/shareA/dirB/mydb.db

Upvotes: 2

Related Questions