1.SQLiteJDBC

SQLite JDBC Driver 可以在这个网站下载https://bitbucket.org/xerial/sqlite-jdbc/overview,当前稳定版本sqlite-jdbc-3.7.2.jar

2. Java 代码

添加sqlite-jdbc-3.7.2.jar,与你添加其他jar包的方法一样。

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6. public class SQLiteTest
  7. {
  8. public static void main(String[] args) throws ClassNotFoundException
  9. {
  10. // load the sqlite-JDBC driver using the current class loader
  11. Class.forName("org.sqlite.JDBC");
  12. Connection connection = null;
  13. try
  14. {
  15. // create a database connection
  16. connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
  17. Statement statement = connection.createStatement();
  18. statement.setQueryTimeout(30);  // set timeout to 30 sec.
  19. statement.executeUpdate("drop table if exists person");
  20. statement.executeUpdate("create table person (id integer, name string)");
  21. statement.executeUpdate("insert into person values(1, 'leo')");
  22. statement.executeUpdate("insert into person values(2, 'yui')");
  23. ResultSet rs = statement.executeQuery("select * from person");
  24. while(rs.next())
  25. {
  26. // read the result set
  27. System.out.println("name = " + rs.getString("name"));
  28. System.out.println("id = " + rs.getInt("id"));
  29. }
  30. }
  31. catch(SQLException e)
  32. {
  33. // if the error message is "out of memory",
  34. // it probably means no database file is found
  35. System.err.println(e.getMessage());
  36. }
  37. finally
  38. {
  39. try
  40. {
  41. if(connection != null)
  42. connection.close();
  43. }
  44. catch(SQLException e)
  45. {
  46. // connection close failed.
  47. System.err.println(e);
  48. }
  49. }
  50. }
  51. }

最新文章

  1. hibernate5.2需要的最少jar文件
  2. [RxJava]在学习RxJava中的错误理解
  3. MySQL学习笔记——多表连接和子查询
  4. JAVA学习之路(环境配置,)
  5. C/C++ 排序&&查找算法(面试)
  6. LintCode-Fast Power
  7. jquery实现可展开收缩的首页大图广告展示方式 泰山压顶代码 V2.0
  8. shell脚本学习积累笔记(第一篇)
  9. ios7新特性1-UI变化、UIKit动态行为支持与Text Kit新接口
  10. Chrome rem bug
  11. CSDN博文大赛火爆开启
  12. 重操JS旧业第二弹:数据类型与类型转换
  13. Python installation
  14. ASP.NET MVC2.0学习笔记:路由设置
  15. jQuery_第二章_定时器
  16. sonar + jacoco + mockMvc 模拟session 用户登录 配合SpringSecurity 权限 快速测试代码覆盖率.
  17. H5之画布canvas小记,以及通过画布实现原子无规则运动
  18. commanderJs编写命令行工具(cli)
  19. Python中使用PyCharm为函数及参数增加注释
  20. mysql 查询优化 ~ 优化基础补充

热门文章

  1. python生成器三元表达式
  2. 对简易网页版注册系统的制作(连接MySQL数据库)
  3. Java 虚拟机程序监控工具软件
  4. Laradock 开放 workspace 端口
  5. IDEA中如何部署tomcat
  6. SpringBoot 解决“不支持发行版本xx”的问题
  7. 100、Java中String类之字符串转为大写
  8. 尝试使用 Visual Studio Online (Cloud IDE)
  9. SciPy 教程
  10. Python3 中 的 绝对导入 与 相对导入