JAVA中的sqlite
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包的方法一样。
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class SQLiteTest
- {
- public static void main(String[] args) throws ClassNotFoundException
- {
- // load the sqlite-JDBC driver using the current class loader
- Class.forName("org.sqlite.JDBC");
- Connection connection = null;
- try
- {
- // create a database connection
- connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
- Statement statement = connection.createStatement();
- statement.setQueryTimeout(30); // set timeout to 30 sec.
- statement.executeUpdate("drop table if exists person");
- statement.executeUpdate("create table person (id integer, name string)");
- statement.executeUpdate("insert into person values(1, 'leo')");
- statement.executeUpdate("insert into person values(2, 'yui')");
- ResultSet rs = statement.executeQuery("select * from person");
- while(rs.next())
- {
- // read the result set
- System.out.println("name = " + rs.getString("name"));
- System.out.println("id = " + rs.getInt("id"));
- }
- }
- catch(SQLException e)
- {
- // if the error message is "out of memory",
- // it probably means no database file is found
- System.err.println(e.getMessage());
- }
- finally
- {
- try
- {
- if(connection != null)
- connection.close();
- }
- catch(SQLException e)
- {
- // connection close failed.
- System.err.println(e);
- }
- }
- }
- }
JAVA中的sqlite的更多相关文章
- 在Java中使用SQLite的教程(转)
简介:这是在Java中使用SQLite的教程的详细页面,介绍了和java,有关的知识.技巧.经验,和一些java源码等. 简单的在Java中使用SQLite的教程 使用SQLiteJDBC封装 www ...
- 在Java中使用Sqlite数据库
一.安装 下载最新的 Sqlite Jdbc 驱动程序jar文件,并添加到Java工程的class路径下: 二.使用 以 sqlite Jdbc 驱动版本为 sqlitejdbc-v56.jar 为例 ...
- Java中数组的特性
转载:http://blog.csdn.net/zhangjg_blog/article/details/16116613 数组是基本上所有语言都会有的一种数据类型,它表示一组相同类型的数据的集合,具 ...
- Android中操作SQLite数据库
我又回到了安卓的学习当中,忙来忙去终于忙的差不多有时间做自己的事情了,这感觉实在是太棒了!!本来想写android的控件以及他们的监视器的,但是我查了查android的手册,基本上都能查到,但是查有些 ...
- 在 Android 应用程序中使用 SQLite 数据库以及怎么用
part one : android SQLite 简单介绍 SQLite 介绍 SQLite 一个非常流行的嵌入式数据库.它支持 SQL 语言,而且仅仅利用非常少的内存就有非常好的性能.此外它还是开 ...
- Android中对sqlite加密--SQLCipher
原文:Android中对sqlite加密--SQLCipher android中有些时候会将一些隐私数据存放在sqlite数据库中,在root过的手机中通过RE就能够轻松的打开并查看数据库所有内容,所 ...
- java中的锁
java中有哪些锁 这个问题在我看了一遍<java并发编程>后尽然无法回答,说明自己对于锁的概念了解的不够.于是再次翻看了一下书里的内容,突然有点打开脑门的感觉.看来确实是要学习的最好方式 ...
- java中的字符串相关知识整理
字符串为什么这么重要 写了多年java的开发应该对String不陌生,但是我却越发觉得它陌生.每学一门编程语言就会与字符串这个关键词打不少交道.看来它真的很重要. 字符串就是一系列的字符组合的串,如果 ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
随机推荐
- 学术Essay写作简单且稳定的架构解析
学术essay写作(academic writing),无论是论文还是专著,间架要稳固,才有可读性,才有说服力. 稳,有几个应然特征:部块(parts)关联紧密:部块不外生枝叶:部块之间没有杂质干扰. ...
- C. Gas Pipeline DP
C. Gas Pipeline time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- C# FileStream 对象的Seek()方法-----转载
原创 kevin617 发布于2010-12-08 11:22:00 阅读数 8630 收藏展开 FileStream 可以随机读写文件 使用 Seek 方法 Seek() ----------有两 ...
- MariaDB——相关概念与sql语句
数据库变量 数据库的两个目录 数据存放目录:/var/lib/mysql/ 配置文件目录:/etc/my.cnf.d/ 查看数据库的变量 show global variables lik ...
- vue移动端transition兼容
vue移动端transition兼容 .face-recognition .wrapper(:style="{height: viewHeight+'px'}") .face-re ...
- vue通过路由传值及在页面刷新后如何保存值
1.普通的路由跳转 方式一:通过routerLinkTo方式,转为a标签的跳转,to里面相当于a标签的href路径 如下: 方式二:通过this.$router.push方式: 如下: 2.带参数的路 ...
- 车林通购车之家--购车计算器模块--算法js
//CarCalculator.js var checkedClass = "jsq-item-check jsq-item-checked"; var uncheckedClas ...
- Mac如何升级自带的vim
brew install vim --with-lua --with-override-system-vi brew install macvim --with-lua --with-override ...
- PHP几个快速读取大文件例子
PHP几个快速读取大文件例子 感谢 把我给崩了 的投递 时间:2014-10-16 来源:三联 在PHP中,对于文件的读取时,最快捷的方式莫过于使用一些诸如file.file_get_contents ...
- Spring JMSTemplate 与 JMS 原生API比较
博客分类: JMS Spring 2.x JMSUtil与Spring JmsTemplate的对比 Author:信仰 Date:2012-4-20 未完待续,截止日期2012-4-20 从以下 ...