Java操作Sqlite数据库-jdbc连接
Java操作Sqlite数据库步骤:
1. 导入Sqlite jdbc
本文使用sqlite-jdbc-3.7.2.jar,下载地址 http://pan.baidu.com/s/1kVHAGdD
2. 编写jdbc连接代码
public class OpSqliteDB {
private static final String Class_Name = "org.sqlite.JDBC";
private static final String DB_URL = "jdbc:sqlite:F:\\xxxdatabase.db";
public static void main(String args[]) {
// load the sqlite-JDBC driver using the current class loader
Connection connection = null;
try {
connection = createConnection();
func1(connection);
System.out.println("Success!");
} catch (SQLException e) {
System.err.println(e.getMessage());
} catch(Exception e) {
e.printStackTrace();
} finally{
try {
if (connection != null)
connection.close();
} catch (SQLException e) {
// connection close failed.
System.err.println(e);
}
}
}
// 创建Sqlite数据库连接
public static Connection createConnection() throws SQLException, ClassNotFoundException {
Class.forName(Class_Name);
return DriverManager.getConnection(DB_URL);
}
public static void func1(Connection connection) throws SQLException {
Statement statement = connection.createStatement();
Statement statement1 = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.
// 执行查询语句
ResultSet rs = statement.executeQuery("select * from table_name1");
while (rs.next()) {
String col1 = rs.getString("col1_name");
String col2 = rs.getString("col2_name");
System.out.println("col1 = " + col1 + " col2 = " + col2);
System.out.println(location);
// 执行插入语句操作
statement1.executeUpdate("insert into table_name2(col2) values('" + col2_value + "')");
// 执行更新语句
statement1.executeUpdate("update table_name2 set 字段名1=" + 字段值1 + " where 字段名2='" + 字段值2 + "'");
}
}
以下是其他的一些Sql语句,来自网址:http://www.cnblogs.com/linjiqin/archive/2011/05/26/2059182.html (Android上面使用Sqlite)
查询语句:
select * from 表名 where 条件子句 group by 分组字句 having ... order by 排序子句
如:
select * from person select * from person order by id desc select name from person group by name having count(*)>
分页SQL与mysql类似,下面SQL语句获取5条记录,跳过前面3条记录
select * from Account limit offset
或者
select * from Account limit ,
插入语句:
insert into 表名(字段列表) values(值列表)
如: insert into person(name, age) values(‘传智’,)
更新语句:
update 表名 set 字段名=值 where 条件子句
如:update person set name=‘传智‘ where id=
删除语句:
delete from 表名 where 条件子句
如:delete from person where id=
Java操作Sqlite数据库-jdbc连接的更多相关文章
- Java操作SQL数据库(JDBC)
0.引入驱动jar包 使用jdbc进行具体操作前,需要引入相关数据库的jar包, 或者使用mave管理依赖 <!-- https://mvnrepository.com/artifact/mys ...
- JDBC访问及操作SQLite数据库
SQLite 是一个开源的嵌入式关系数据库,其特点是高度便携.使用方便.结构紧凑.高效.可靠. 与其他数据库管理系统不同,SQLite 的安装和运行非常简单,在大多数情况下,只要确保SQLite的二进 ...
- Java应用程序连接数据库--JDBC基础
Java应用程序连接数据库--JDBC基础 Java应用程序连接数据库–JDBC基础 <!-- MySQL驱动,连接数据库用,由数据库厂商提供 --> <dependency&g ...
- 总结java操作MySQL 即JDBC的使用
java.sql包中存在DriverManager类,Connection接口,Statement接口和ResultSet接口.类和接口作用如下: DriverManager:主要用于管理驱动程序和连 ...
- 如何C#操作SQLite数据库
或许有人之前在java开发中使用过SQLite,对它有些印象.在用Winform或Wpf开发小应用程序时,发现用SQLite数据库也是不错的.就像一个会员管理软件,开发完毕后,可以省去想sqlserv ...
- Python 操作 SQLite 数据库
写在之前 SQLite 是一个小型的关系型数据库,它最大的特点在于不需要单独的服务.零配置.我们在之前讲过的两个数据库,不管是 MySQL 还是 MongoDB,都需要我们安装.安装之后,然后运行起来 ...
- Qt 操作SQLite数据库
项目中通常需要采用各种数据库(如 Qracle.SQL Server.MySQL等)来实现对数据的存储.查询等功能.下面讲解如何在 Qt 中操作 SQlite 数据库. 一.SQLite 介绍 Sql ...
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
1.android下junit测试框架配置 单元测试需要在手机中进行安装测试 (1).在清单文件中manifest节点下配置如下节点 <instrumentation android:name= ...
- EF6操作Sqlite数据库的项目兼容性问题
vs2010无法正确打开2015创建的项目里面操作Sqlite数据库时使用EF6创建的edmx文件(会显示空白) 但是可以正常查询 vs2015无法正确打开2010创建的项目里面操作Sqlite数 ...
随机推荐
- 一个基于jQuery的移动端条件选择查询插件(原创)
下载插件 目前给出的下载是混淆了后的代码 愿意一起探讨的可以找我要源码 使用方式: var ConditionsChoose = $("#Screening").Condition ...
- python1
leetcode上面的很简单的题目 Given an integer (signed 32 bits), write a function to check whether it is a power ...
- Unity学习疑问记录之 动作动画忽略timeScale
http://www.bubuko.com/infodetail-968864.html
- datatables服务器端分页要点
背景:当要查询大量数据的时候,有datatables自身的分页,明显查询比较慢,这是要使用服务器端分页 参数:"bServerSide": true, "fnServer ...
- 【转】Apache 配置虚拟主机三种方式
Apache 配置虚拟主机三种方式 原文博客http://www.cnblogs.com/hi-bazinga/archive/2012/04/23/2466605.html 一.基于IP 1. 假 ...
- 企业IT管理员IE11升级指南【1】—— Internet Explorer 11增强保护模式 (EPM) 介绍
企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...
- yar框架使用笔记
Yar是什么 Yar是并行的RPC框架(Concurrent RPC framework),Laruence开发. 安装 下载地址:http://pecl.php.net/package/yar wi ...
- MongoDB 安装和可视化工具
MongoDB 是一款非常热门的NoSQL,面向文档的数据库管理系统,官方下载地址是:MongoDB,博主选择的是 Enterprise Server (MongoDB 3.2.9)版本,安装在Win ...
- SQL Server 2014新特性探秘(3)-可更新列存储聚集索引
简介 列存储索引其实在在SQL Server 2012中就已经存在,但SQL Server 2012中只允许建立非聚集列索引,这意味着列索引是在原有的行存储索引之上的引用了底层的数据,因此会 ...
- [汇编与C语言关系]2. main函数与启动例程
为什么汇编程序的入口是_start,而C程序的入口是main函数呢?以下就来解释这个问题 在<x86汇编程序基础(AT&T语法)>一文中我们汇编和链接的步骤是: $ as hell ...