How to include SQLite database in executable Jar

0 votes

I have created a Swing application that uses SQLite as a local database. The database file is located in project's root directory.

Project/DatabaseFile

The application runs fine on Eclipse, but when I run the packaged executable Jar, I get the following error:

No such table : table1

This means that the database is not reachable. When I examined the contents of the resulting JAR file, the database file was not there anymore.

In the code, I've linked the database as follows:

jdbc:sqlite:DatabaseFile

My question is, how to include the SQLite database in the executable Jar?

May 8, 2020 in Java by kartik
• 37,510 points
3,680 views

1 answer to this question.

0 votes

Hello @kartik,

I have found two different ways to name the filepath depending on how you are trying to access it.

 Assuming you are accessing the db is located in "/yourproject/resource/ or /yourproject/bin/resource" you should use this as your path:

//Eclipse test path
String url = "jdbc:sqlite:resource/mydb.db";

or

//runnable jar path
String url = "jdbc:sqlite::resource:mydb.db";

then

mysqlitedatasource.setUrl(url);

Your way also works... by putting the db in /src

Thank You!!

answered May 8, 2020 by Niroj
• 82,880 points

Related Questions In Java

+4 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,120 points
351,474 views
0 votes
1 answer

How to run the JAR files in windows?

Following are the steps to run the ...READ MORE

answered May 28, 2018 in Java by Parth
• 4,630 points
889 views
0 votes
2 answers

How can we add the local JAR files to the Maven Project in Java?

Firstly I would like to give credit ...READ MORE

answered Nov 5, 2018 in Java by Sushmita
• 6,910 points
10,168 views
0 votes
1 answer

How to run a JAR file in Java?

The command given below will help you ...READ MORE

answered Jun 1, 2018 in Java by Parth
• 4,630 points
7,127 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
1 answer

how to do global variable declaration in java

Hello,​ Global varriable which is defined after the ...READ MORE

answered Apr 3, 2020 in Java by Niroj
• 82,880 points
459 views
0 votes
2 answers

How to convert InputStream to byte array in Java?

The class IOUtils, lib: https://mvnrepository.com/artifact/com ...READ MORE

answered Sep 24, 2020 in Java by Anthony
14,689 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP