官方示例https://bitbucket.org/xerial/sqlite-jdbc
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
//建立一个数据库名lincj.db的连接,如果不存在就在当前目录下创建之
conn = DriverManager.getConnection("jdbc:sqlite:lincj.db");
Statement state = conn.createStatement();
state.setQueryTimeout(30);
state.executeUpdate("drop table if exists person");
state.executeUpdate("create table person(id integer,name string)");
state.executeUpdate("insert into person values(1, 'leo')");
state.executeUpdate("insert into person values(2, 'yui')");
ResultSet rs = state.executeQuery("select * from person");
while (rs.next())
System.out.println("ID:"+rs.getInt("id")+"---"+"名字:"+rs.getString("name"));
}
catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}