<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.16.1</version>
</dependency>
@H_403_0@pom.xml @H_403_0@引入这个jar @H_403_0@代码
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)
- linux (java)
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@H_403_0@source .bashrc @H_403_0@编译,执行,查看 原文链接:https://www.f2er.com/sqlite/198590.html