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,520 points
4,262 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,840 points

Related Questions In Java

+5 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,140 points
359,814 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,640 points
1,143 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,920 points
11,795 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,640 points
7,423 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,438 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,840 points
722 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
15,606 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