资料
https://www.sqlite.org/download.html
https://www.sqlite.org/2017/sqlite-dll-win64-x64-3160200.zip
http://mvnrepository.com/search?q=org.sqlite.JDBC
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.16.1</version>
</dependency>
pom.xml
引入这个jar
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class sqliteTest { public static void main(String[] args) { Connection conn = null; ResultSet rs = null; try { Class.forName("org.sqlite.JDBC"); conn = DriverManager.getConnection("jdbc:sqlite:yzc.db"); Statement stat = conn.createStatement(); stat.executeUpdate("drop table if exists tbl1;"); stat.executeUpdate("create table if not exists tbl1(name varchar(20),salary int,PRIMARY KEY (`name`));"); stat.executeUpdate("replace into tbl1(name,salary) values('ZhangSan',8000);"); stat.executeUpdate("replace into tbl1(name,salary) values('LiSi',7800);"); stat.executeUpdate("replace into tbl1(name,salary) values('WangWu',5800);"); stat.executeUpdate("replace into tbl1(name,salary) values('ZhaoLiu',9100);"); rs = stat.executeQuery("select * from tbl1;"); while (rs.next()) { System.out.print("name = " + rs.getString("name") + " "); System.out.println("salary = " + rs.getString("salary")); } } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } finally { try { rs.close(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } try { conn.close(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } } } }
- windows (java)
eclipse控制台
- linux (java)
.bashrc 配置 sqlite 库
vi .bashrc
test -s ~/.alias && . ~/.alias || true export JAVA_HOME=/opt/jdk1.7.0_76 export JRE_HOME=$JAVA_HOME/jre export LANG=zh_CN export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK" export PATH=${JAVA_HOME}/bin:${PATH} export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/sqlite-jdbc-3.16.1.jar
source .bashrc
编译,执行,查看
原文链接:https://www.f2er.com/sqlite/198590.html