2016年11月2日 星期三

SQLite with Java in Eclipse


Download JAR
Download sqlite-jdbc-3.14.2.jar from bit bucket https://bitbucket.org/xerial/sqlite-jdbc/downloads


Create Project
Eclipse > File > New > Java Project > Project Name = SQLiteJDBC













































Copy JAR File
Project > Right Click > New > Folder > lib > Right Click > Import > File System > from "Downloads" > select the downloaded JAR file


































Add JAR to Build Path Libraries
Project > Right Click > Properties > Libraries > Add JARs






























New Class
Project > Right Click > New > Class > Package = "com.sqlite.jdbc", Name = "SQLiteJDBC"


Code


package com.sqlite.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;

public class SQLiteJDBC {
       public static void main(String[] args) {
              Connection c = null;
              try {
                     Class.forName("org.sqlite.JDBC");
                     //c = DriverManager.getConnection("jdbc:sqlite:mdp.db"); // current directory
                     c = DriverManager.getConnection("jdbc:sqlite:data/mdp.db"); // data directory
              }
              catch (Exception e) {
                     System.err.println(e.getClass().getName() + ": " + e.getMessage());
                     System.exit(0);
              }
              System.out.println("Opened database successfully");
       }

}



Run
SQLiteJDBC.java > Right Click > Run As > Java Application

Opened database successfully







沒有留言:

張貼留言

2023 Promox on Morefine N6000 16GB 512GB

2023 Promox on Morefine N6000 16GB 512GB Software Etcher 100MB (not but can be rufus-4.3.exe 1.4MB) Proxmox VE 7.4 ISO Installer (1st ISO re...