java web sqllite_sqllite java 下载地址

mportjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassSample{publicstaticvoidmain(String[]args)throwsClassNotFoundException{// load the sqlite-JDBC driver using the current class loaderClass.forName("org.sqlite.JDBC");Connectionconnection=null;try{// create a database connectionconnection=DriverManager.getConnection("jdbc:sqlite:sample.db");Statementstatement=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')");ResultSetrs=statement.executeQuery("select * from person");while(rs.next()){// read the result setSystem.out.println("name = "+rs.getString("name"));System.out.println("id = "+rs.getInt("id"));}}catch(SQLExceptione){// if the error message is "out of memory",// it probably means no database file is foundSystem.err.println(e.getMessage());}finally{try{if(connection!=null)connection.close();}catch(SQLExceptione){// connection close failed.System.err.println(e);}}}}

How to Specify Database Files

Connectionconnection=DriverManager.getConnection("jdbc:sqlite:C:/work/mydatabase.db");

How to Use Memory Databases

Connectionconnection=DriverManager.getConnection("jdbc:sqlite::memory:");

AddedREAD_UNCOMMITTEDmode support for better query performance: (see alsohttp://www.sqlite.org/sharedcache.html)

// READ_UNCOMMITTED mode works only in shared_cache mode.Propertiesprop=newProperties();prop.setProperty("shared_cache","true");Connectionconn=DriverManager.getConnection("jdbc:sqlite:",prop);conn.setTransactionIsolation(Conn.TRANSACTION_READ_UNCOMMITTED);

Using SQLiteJDBC with Maven2

org.xerialsqlite-jdbc3.7.2

Using SQLiteJDBC with Tomcat6 Web Server

Do not include sqlite-jdbc-(version).jar in WEB-INF/lib folder of your web application package, since multiple web applications hosted by the same Tomcat server cannot load the sqlite-jdbc native library more than once. That is the specification of JNI (Java Native Interface). You will observe UnsatisfiedLinkError exception with the message "no SQLite library found".

Work-around of this problem is to put sqlite-jdbc-(version).jar file into (TOMCAT_HOME)/libdirecotry, in which multiple web applications can share the same native library file (.dll, .jnilib, .so) extracted from this sqlite-jdbc jar file.

If you are using Maven for your web application, set the dependency scope as 'provided', and manually put the SQLite JDBC jar file into (TOMCAT_HOME)/lib folder.org.xerialsqlite-jdbc3.7.2provided

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值