Connecting to SQLite Database in a Java Web Application

Posted on by By Ramu Vudugula, in Databases | 0

Summary: This tutorial shows step by step procedure to connect SQLite database using JDBC driver

Make data easy with Helical Insight.
Helical Insight is world’s best open source business intelligence tool.

Lets Register For Live Demo

  1. Connecting to SQLite database in java application
    1. To connect sqlite database in Java, we need SQLite JDBC driver. Download the latest driver using the below link
    2. https://bitbucket.org/xerial/sqlite-jdbc/downloads/

    3. Add the downloaded jar as an external jar in the project
    4. The SQLite JDBC driver allows you to load an SQLite database from the file system using the following connection string
    5. Connection string: jdbc:sqlite: sqlite_database_file_path

    6. Create a java class add the below code to connect SQLite database
    7. The output of the above code gives the below result

  2. Connecting to SQLite database in a java web application

Make data easy with Helical Insight.
Helical Insight is world’s best open source business intelligence tool.

Click Here to Free Download

In the previous step, we have created a java method to connect the sqlite database in java application. Here we are trying similar steps in a java web application.

A Java web application is a collection of dynamic resources (such as Servlets, JavaServer Pages, Java classes and jars) and static resources (HTML pages and pictures) which can be run on tomcat server.

  1. Create a dynamic web application in Java, create a package and add the above-created java class in the src folder
  2. Add SQLite JDBC driver as an external jar in the resources folder
  3. Add SQLite JDBC driver in lib folder present in the web-inf folder
  4. Create a JSP page and import the java class, call the database connection method
  5. Run the JSP page on tomcat server and check the console. We are getting an error as “No suitable driver found for jdbc:sqlite:E:/Workspace/Softwares/sqlite-db-326/db/chinook.db” but we have added SQLite JDBC driver as an external jar and in the lib folder (refer step 2 and step 3)
  6. To fix the above issue add the class name for the SQLite JDBC driver in the getConnection java method
    Class name: Class.forName(“org.sqlite.JDBC”)
  7. Make data easy with Helical Insight.
    Helical Insight is world’s best open source business intelligence tool.

    Get your 30 Days Trail Version

  8. Now restart the tomcat server and run the JSP page
  9. We can see that connection to SQLite database success message in the console and connection object in the JSP page

In case if you have any queries please get us at support@helicaltech.com

Thank You
Ramu Vudugula
Helical IT Solutions Pvt Ltd

logo

Best Open Source Business Intelligence Software Helical Insight Here

logo

A Business Intelligence Framework


logo

Best Open Source Business Intelligence Software Helical Insight is Here

logo

A Business Intelligence Framework

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments