使用SQLite3开发java应用程序

前端之家收集整理的这篇文章主要介绍了使用SQLite3开发java应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

使用SQLite3开发java应用程序

sqlite数据库的JDBC
这里给出一个中文站点的URL:
http://www.sqlite.com.cn/Upfiles/source/sqlitejdbc-v033-nested.tgz

将下载到的包解压后得到jar包 sqlitejdbc-v033-nested.jar 放到%JAVA_HOME%/lib 下,
并且将其添加到classpath系统环境变量中,我的classpath系统环境变量现在为:
.;%JAVA_HOME%/lib/sqlitejdbc-v033-nested.jar
在你的代码中引用这个驱动:
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:filename");//filename为你的sqlite数据名称
// ... use the database ...
conn.close();

示例程序如下:
@H_408_403@ @H_877_404@

编译运行:


E:/Coding/java/test>javac Testsqlite.java

E:/Coding/java/test>java Testsqlite
name = ZhangSan salary = 8000
name = LiSi salary = 7800
name = WangWu salary = 5800
name = ZhaoLiu salary = 9100
总结:本文介绍了嵌入式数据库sqlite在Java中的应用,
通过创建表、插入数据、查询等操作介绍了在Java中对数据库的操纵。

sqlite3命令操作大全 ========================================================>>

.数据库、表的建立,记录的添加查询修改删除

F:/>sqlite3 database.db
sqlite> create table admin(username text,age integer);
sqlite> insert into admin values('kuang',25);
sqlite> select * from admin;
sqlite> update admin set username='kk',age=24 where username='kuang' and age=25;
sqlite> delete from admin where username='kk';

注:每条sql语句后必须以";"号结尾!

2.sqlite系统命令

.bail ON|OFF Stop after hitting an error.Default OFF
.databases List names and files of attached databases(查看目前挂的数据库)
.dump ?TABLE? ...Dump the database in an sql text format(以sql格式输出表结构)
.echo ON|OFF Turn command echo on or off
.exitExit this program(退出程序)
.explain ON|OFFTurn output mode suitable for EXPLAIN on or off.
.header(s) ON|OFFTurn display of headers on or off
.helpShow this message(显示帮助信息)
.import FILE TABLE Import data from FILE into TABLE(把文件中的数据导入到表中,各字段用separator的值为分隔符)
.indices TABLE Show names of all indices on TABLE
.load FILE ?ENTRY? Load an extension library
.mode MODE ?TABLE? Set output mode where MODE is one of:(输出格式)
csvComma-separated values(各字段以逗号为分隔符输出)
column Left-aligned columns.(See .width)(以.width设置的宽度显示各字段)
html HTML <table> code(html表格格式输出)
insert sql insert statements for TABLE(以insert sql语句形式输出)
line One value per line(field = value的形式逐行输出)
list Values delimited by .separator string(各字段以separator的值为分隔符输出)
tabs Tab-separated values
tclTCL list elements
.nullvalue STRINGPrint STRING in place of NULL values
.output FILENAME Send output to FILENAME(设置把查询输出文件,后面的输出结果都保存到文件中)
.output stdout Send output to the screen(设置把查询结果输出到屏幕,默认)
.prompt MAIN CONTINUEReplace the standard prompts(修改提示符)
.quitExit this program(退出)
.read FILENAME Execute sql in FILENAME(执行文件中的sql语句)
.schema ?TABLE?Show the Create statements(以sql格式输出表结构)
.separator STRINGChange separator used by output mode and .import(修改分隔符)
.showShow the current values for var@R_301_437@s settings(显示配置信息)
.tables ?PATTERN?List names of tables matching a LIKE pattern(看看有创建了多少表)
.timeout MSTry opening locked tables for MS milliseconds(超时时间,单位:毫秒)
.width NUM NUM ... Set column widths for "column" mode(设置列宽)

引用自:http://blog.csdn.net/sdlcgxcqx/article/details/4437776
原文链接:https://www.f2er.com/sqlite/200800.html

猜你在找的Sqlite相关文章

importjava . sql . *;
import org . sqlite. JDBC;

public class Testsqlite
{
public staticvoid main( String [ ] args)
{
try
{
//连接sqlite的JDBC

Class .forName ( "org.sqlite.JDBC" ) ;

//建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之

Connection conn = DriverManager . getConnection ( "jdbc:sqlite:zieckey.db" ) ;

Statement stat = conn. createStatement( ) ;

stat. executeUpdate( "create table tbl1(name varchar(20),salary int);") ; //创建一个表,两列


stat. executeUpdate( "insert into tbl1 values('ZhangSan',8000);") ; //插入数据

stat. executeUpdate( "insert into tbl1 values('LiSi',7800);") ;
stat. executeUpdate( "insert into tbl1 values('WangWu',5800);") ;
stat. executeUpdate( "insert into tbl1 values('ZhaoLiu',9100);") ;

ResultSet rs = stat. executeQuery( "select * from tbl1;") ; //查询数据

while ( rs.next ( ) ) {//将查询到的数据打印出来

System . out. print( "name = "+ rs. getString ( "name" ) +" " ) ; //列属性

System . out. println( "salary = "+ rs. getString ( "salary" ) ) ; //列属性

}
rs. close( ) ;
conn. close( ) ; //结束数据库的连接

}
catch (Exception e )
{
e. printStackTrace( ) ;
}
}
}