Summary: in this tutorial, we will show you how to download SQLite JDBC Driver and connect to the SQLite database via JDBC.
Download SQLite JDBC Driver
I use Liya from the Mac App Store, it's free, does the job, and the project is maintained (a month or so between updates as of Jan 2013). I also test a lot on the device. You can access the SQLITE database on the device. Aug 14, 2020 Download the latest version of SQLite for Mac - SQL database connection development library. Read 3 user reviews of SQLite on MacUpdate. Download SQLiteStudio for Mac - A straightforward and easy to use, yet powerful SQLite database manager that makes it easy for you to manage and edit databases.
To download the latest version of SQLite JDBC Driver, you go to the download page. You should download the latest version of the driver. At the time of this writing, the latest version is
sqlite-jdbc-3.27.2.1.jar
.The JAR file includes both Java class files and SQLite binaries for Mac OX S, Linux, and Windows, Both 32-bit and 64-bit.
SQLite connection strings
The SQLite JDBC driver allows you to load an SQLite database from the file system using the following connection string:
The
sqlite_data_file_path
is the path to the SQLite database file, which is either relative or absolute path as follows:Or
To connect to an in-memory database, you use the following connection string:
Connect to an SQLite database via JDBC
Step 1
Create a new directory called java under
c:sqlite
Step 2
Inside the
java
folder create a new folder called connect
.Step 3
Copy the jar file
sqlite-jdbc-3.27.2.1.jar
to the c:sqliteconnect
folder.Step 4
Create a new subfolder called
net
inside c:sqliteconnect
and another subfolder called sqlitetutorial
inside the net
folder.Step 5
Create a new file named
Connect.java
in the sqlitetutorial
folder with the following contents. The program will connect to the chinook.db
database located in the c:sqlitedb
folder.Note that you should have the chinook.db file downloaded and copied to the
C:/sqlite/db/
folder.Step 6
Launch the command line window and navigate to the
sqlitetutorial
subfolder created above using the following command:Step 7
Compile the
Connect.java
file using the following command:You will see a new class file generated:
Note that your JDK must be on the PATH, otherwise you will get an error.
Step 8
Change the current directory to the
connect
directory:Step 9
Run the
net.sqlitetutorial.Connect
class using the following command:Here is the output:
It works as expected.
Troubleshooting
If you receive the following message, you should have missed step 8:
How the program works
In the
connect()
method:Sqlitestudio Mac
First, declare a variable that holds a connecting string to the sqlite database
c:sqlitedbchinook.db
Next, use the
DriverManager
class to get a database connection based on the connection string.![Install sqlite3 Install sqlite3](/uploads/1/2/6/4/126479978/458660666.jpg)
Then, trap any
SQLException
in the try catch
block and display the error message.After that, close the database connection in the
finally
block.Finally, call the
connect()
method in the main()
method of the Connect
class.In this tutorial, you have learned step by step how to use the SQLite JDBC driver to connect to an SQLite database from a Java program.
- SQLite Tutorial
- Advanced SQLite
- SQLite Interfaces
- SQLite Useful Resources
- Selected Reading
SQLite is famous for its great feature zero-configuration, which means no complex setup or administration is needed. This chapter will take you through the process of setting up SQLite on Windows, Linux and Mac OS X.
Install SQLite on Windows
- Step 1 − Go to SQLite download page, and download precompiled binaries from Windows section.
- Step 2 − Download sqlite-shell-win32-*.zip and sqlite-dll-win32-*.zip zipped files.
- Step 3 − Create a folder C:>sqlite and unzip above two zipped files in this folder, which will give you sqlite3.def, sqlite3.dll and sqlite3.exe files.
- Step 4 − Add C:>sqlite in your PATH environment variable and finally go to the command prompt and issue sqlite3 command, which should display the following result.
Install SQLite on Linux
Today, almost all the flavours of Linux OS are being shipped with SQLite. So you just issue the following command to check if you already have SQLite installed on your machine.
If you do not see the above result, then it means you do not have SQLite installed on your Linux machine. Following are the following steps to install SQLite −
- Step 1 − Go to SQLite download page and download sqlite-autoconf-*.tar.gz from source code section.
- Step 2 − Run the following command −
The above command will end with SQLite installation on your Linux machine. Which you can verify as explained above.
Install SQLite on Mac OS X
Install Sqlite3
Though the latest version of Mac OS X comes pre-installed with SQLite but if you do not have installation available then just follow these following steps −
- Step 1 − Go to SQLite download page, and download sqlite-autoconf-*.tar.gz from source code section.
- Step 2 − Run the following command −
The above procedure will end with SQLite installation on your Mac OS X machine. Which you can verify by issuing the following command −
Finally, you have SQLite command prompt where you can issue SQLite commands for your exercises.