Chinaunix首页 | 论坛 | 博客
  • 博客访问: 52901
  • 博文数量: 18
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 10:18
文章分类

全部博文(18)

文章存档

2011年(1)

2010年(14)

2009年(3)

我的朋友
最近访客

分类: Java

2009-11-26 21:46:37

1.去网站下载sqlitejdbc.根据自已需要,下载sqlitejdbc.(sqlitejdbc有两个版本,一种是pure的一种是native的。native的速度快。它放在**-bin.tgz里。我下的就是这种

2. 下载后解压
,有以下几个文件: libsqlitejdbc.so,sqlitejdbc.dll,
libsqlitejdbc.jnilibsqlitejdbc-v056-native.jar
其中libsqlitejdbc.so是linux下的动态链接库,
sqlitejdbc.dll是windows下的动态链接库, libsqlitejdbc.jnilib是Mac下的动态链接库

3.根据自已的操作系统将
sqlitejdbc-v056-native.jar与对应动态链接库放到jdk/jre/lib/ext里。(我的是linux,则将sqlitejdbc-v056-native.jar 与libsqlitejdbc.so 放到jdk/jre/lib/ext中)

3.如果你只是随便的将sqlitejdbc.jar放在任一目录,并且你又是run in pure-java mode(纯java模式下运行?是这么译吗)
请参考

4.如果你已看了第三步的网站,以下可以不用看了,下面的介绍只是复述3里面的而已。

5.转自 的实例经验证可以运行。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Sample
{
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);
}
}
}
}
6.sqlite中国网站,不过这网站不爽,动不动就要求你登陆(如果你没登陆的话)。
阅读(1920) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-11-01 16:05:37

方法管用,用native比nested快了10倍左右。