Julian Schmuckli Julian Schmuckli -4 years ago 70
Java Question

Set path to a jdbc SQLite database, where it will be located

I am using the following script to connect to a local SQLite database in Java:

public static Connection createOrOpenDatabase(String database) {

String url = "jdbc:sqlite:" + database;

try {
Connection conn = DriverManager.getConnection(url);
return conn;
} catch (SQLException e) {
return null;

So this works pretty good and it saves it in the same directory, where also the
is located. Now is my question, how can I set a absolute path, where the database is located.

For example the current location of the
file is:


Now I want to save this file to the user.home directory:


How can I achieve this?

Answer Source

how can I set a[n] absolute path

You can just include it as part of the connection URL, e.g.,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download