【文件属性】:
文件名称:SQLite数据库 sqlitedll库文件 sqlite驱动JAR包 sqlite工具
文件大小:3.61MB
文件格式:ZIP
更新时间:2013-09-15 17:03:24
SQLite数据库 sqlitedll库文件 sqlite驱动JAR包 sqlite工具
在Java下连接SQLite数据库
一、下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/
二、将下载到的包解压后得到jar包放到%JAVA_HOME%\lib下,并且将其添加到ClassPath系统环境变量中。一定要保证在类路径ClassPath中有该jar包,并且保证在JAVA库路径JAVA Library Path中有本地库Native Library(\workspace\"Web应用"\WebRoot\WEB-INF\lib\下最好也要加入该jar包)。"SQLite.JDBCDriver"作为JDBC的驱动程序类名。连接JDBC的URL格式为jdbc:sqlite:/path。这里的path为指定到SQLite数据库文件的路径,例如:
jdbc:sqlite://dirA/dirB/dbfile
jdbc:sqlite://DRIVE:/dirA/dirB/dbfile
jdbc:sqlite://COMPUTERNAME/shareA/dirB/dbfile
三、下面是使用SQLite的两段代码以供参考:
代码段1:
1 import java.sql.*;
2 import org.sqlite.JDBC;
3
4 public class SQLiteTest {
5 public static void main(String[] args) {
6 try {
7 // The SQLite (3.3.8) Database File
8 // This database has one table (pmp_countries) with 3 columns (country_id, country_code, country_name)
9 // It has like 237 records of all the countries I could think of.
10 String fileName = "c:/pmp.db";
11 // Driver to Use
12 // http://www.zentus.com/sqlitejdbc/index.html
13 Class.forName("org.sqlite.JDBC");
14 // Create Connection Object to SQLite Database
15 // If you want to only create a database in memory, exclude the +fileName
16 Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName);
17 // Create a Statement object for the database connection, dunno what this stuff does though.
18 Statement stmt = conn.createStatement();
19 // Create a result set object for the statement
20 ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC");
21 // Iterate the result set, printing each column
22 // if the column was an int, we could do rs.getInt(column name here) as well, etc.
23 while (rs.next()) {
24 String id = rs.getString("country_id"); // Column 1
25 String code = rs.getString("country_code"); // Column 2
26 String name = rs.getString("country_name"); // Column 3
27 System.out.println("ID: "+id+" Code: "+code+" Name: "+name);
28
29 }
30 // Close the connection
31 conn.close();
32 }
33 catch (Exception e) {
34 // Print some generic debug info
35 System.out.println(e.getMessage());
36 System.out.println(e.toString());
37 }
38 }
39 }
代码段2:
1 import java.sql.*;
2 import org.sqlite.JDBC;
3 /**
4 * 这是个非常简单的SQLite的Java程序,
5 * 程序中创建数据库、创建表、然后插入数据,
6 * 最后读出数据显示出来
7 * @author zieckey (http://zieckey.cublog.cn)
8 */
9 public class TestSQLite{
10 public static void main(String[] args){
11 try{
12 //连接SQLite的JDBC
13 Class.forName("org.sqlite.JDBC");
14 //建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之
15 Connection conn = DriverManager.getConnection("jdbc:sqlite:zieckey.db");
16 Statement stat = conn.createStatement();
17
18 stat.executeUpdate( "create table tbl1(name varchar(20), salary int);" );//创建一个表,两列
19 stat.executeUpdate( "insert into tbl1 values('ZhangSan',8000);" ); //插入数据
20 stat.executeUpdate( "insert into tbl1 values('LiSi',7800);" );
21 stat.executeUpdate( "insert into tbl1 values('WangWu',5800);" );
22 stat.executeUpdate( "insert into tbl1 values('ZhaoLiu',9100);" );
23
24 ResultSet rs = stat.executeQuery("select * from tbl1;"); //查询数据
25
26 while (rs.next()) { //将查询到的数据打印出来
27 System.out.print("name = " + rs.getString("name") + " "); //列属性一
28 System.out.println("salary = " + rs.getString("salary")); //列属性二
29 }
30 rs.close();
31 conn.close(); //结束数据库的连接
32 }
33 catch( Exception e )
34 {
35 e.printStackTrace ( );
36 }
37 }
38 }
【文件预览】:
sqlitedll-3_7_2.zip
sqlitejdbc-v056.jar
sqlite-3_7_2.zip
sqlite3_analyzer-3.7.1-win32.zip
网友评论
- 谢谢分享,比较全
- 好资源感谢分享
- 可以,是我需要的东西
- 好用的东西
- 非常不错,很好用啊
- 可以用,非常不错,完美解决了驱动问题
- 下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/
- 东西比较全,也都可以用,谢谢
- 好用的东东,占用资源少,非常方便。
- 谢谢分享,非常好用,学习了。 .
- 谢谢分享,非常好用
- 谢谢分享,非常好用
- 资源很好啊,谢谢。。。
- 不错 可以用 3Q
- 非常不错,很好用啊
- 非常不错,很好用啊
- 非常不错,很好用啊
- 非常的不错
- 好东西值得分享
- 官网上下载不了 没想到这里还有 大赞
- 能用,谢谢分享
- 很实用的资源
- 简要看了下,很完整,很不错。
- 不错,顺利的使用上了。很实用的东西
- 很实用的东西
- 好用,里面的工具不太会用。。。
- jar包在项目中可以正常使用,感谢
- 非常好,解决了我的问题!!
- 谢谢分享,非常好用
- 很实用的资源,不错哦