SQLite Java NetBeans Tutorial : how to create connection java using SQLite Java NetBeans IDE and using JDBC-SQLite library to connect with SQLite Databases?
SQLite Java Tutorials : How to create java connection using SQLite embedded database using NetBeans IDE? NetBeans IDE can handle SQLite for connection with java using JDBC Sqlite Library, We can access SQLite database from java using SQLite Jdbc Library.
Please Read :
After you download the .jar file, just include it to our Java project, then you must have a database (SQLite) included into our project too, just copy your DB file to : NetBeansProjects\ProjectName\src\javaapplication1
Now, we can create source code for out connection to SQLite database,
Source code Java Connection
A UNIX (Linux, Mac OS X, etc) file /home/leo/work/mydatabase.db
See you next sessions
Please Read :
- How to connect Java to MySQL database?
- How to creatu CRUD operations with MySQL Database
- How to Install SQLite on windows?
How to Connect with SQLite Embedded Database?
we need SQLite Jdbc Library to connect to database and include this library to our Java project in the NetBeans IDE, download JDBC SQLite Library Driver here https://bitbucket.org/xerial/sqlite-jdbcAfter you download the .jar file, just include it to our Java project, then you must have a database (SQLite) included into our project too, just copy your DB file to : NetBeansProjects\ProjectName\src\javaapplication1
Now, we can create source code for out connection to SQLite database,
Source code Java Connection
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.awt.HeadlessException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author hc-kr.com
*/
public class JavaApplication1 {
Connection conn = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
ConnectDB();
}
public static Connection ConnectDB(){
try {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:crud.s3db");
JOptionPane.showMessageDialog(null,"Connection Success!");
return conn;
} catch (ClassNotFoundException | SQLException | HeadlessException e) {
JOptionPane.showMessageDialog(null, "Connection failed ! " + e);
return null;
}
}
}
How to Specify Database Files?
Here is an example to select a file C:\Doc\mydatabase.db (in Windows)
Connection connection = DriverManager.getConnection("jdbc:sqlite:C:/work/mydatabase.db");
A UNIX (Linux, Mac OS X, etc) file /home/leo/work/mydatabase.db
Connection connection = DriverManager.getConnection("jdbc:sqlite:/home/b0x/mydatabase.db");
How to Use Memory Databases?
SQLite supports on-memory database management, which does not create any database files. To use a memory database in your Java code, get the database connection as follows :
Connection connection = DriverManager.getConnection("jdbc:sqlite::memory:");
See you next sessions
COMMENTS