By Shoaib in: Java // August 25, 2011
Embedding the database within the Application is really a good idea ,to get the things work out as planned you need a correct choice,using SQLite you can embed the database within the jar file along with the Application,unlike Derby it doesn’t creates a dabase outside the Application JAR but instead you can have it within the Application JAR,Firstly you need a JDBC driver for making a connection to the SQLite database with JAVA, Download the ‘sqlite-jdbc-3.7.2.jar’,which is the latest one as of for now,but check to see if there is another release from SQLite,This version supports “jdbc:sqlite::resource:” syntax to access read-only DB files contained in JAR archives, or external resources specified via URL, local files address etc.
TO Configure the DataBase ,create an Object of SQLiteConfig class and set read Only property to false and now you can connect to and write or read from the database,the important thing to note here is that you need the sqlite-jdbc JAR not only during compiling but also at the run time,so don’t forget to extrat the JAR file and add into the application JAR
*author : shoaib
public class ConnectingSQLite
private Connection conn;
public static void main(String args)
SQLiteConfig config =
conn = ds.getConnection();
//This method return more than one error from SQL,
System.out.println("SQLError: "+se.getMessage()+" code: "
+se.getErrorCode()+" SQL State: "+se.getSQLState());