Java with SQLite
To use SQLite with java programs, you must have SQLite JDBC Driver and Java set up on the system. Follow the steps given below:
Connect to SQLite Database
Use the following code to connect to SQLite database using Java programming language:
It is connected with your already created database JTP.db.
Create Database using java
You can also create a new database in SQLite using java programming language. Let's create a database named "SSSIT.db". Create a public class "Create" and use the following code:
A new database named "SSSIT.db" is created now. You can see it where you have installed sqlite.
Create a table using java
Let's create a table named "employees" having columns "name" and "capacity". Create a class name "CreateTable", having the following code:
It will create a table "employees" within the SSSIT.db database.
Insert Record in the table
After the creation of the table, use the following code to insert some records in the table. Create a new class "InsertRecords", having the following code:
Now record is inserted in the table. You can check it out by using the SELECT command:
To select records from the table, use the following code. Create a new class "SelectRecords", having the following data.
You can see that it displays all the records we inserted once.
Note: By using the same procedure, you can update and delete the table and database.