关于java中连接sqlite的有关问题

我按如下步骤执行:

一、下载SQLite数据库的JDBC:http://www.zentus.com/sqlitejdbc/

二、将下载到的包解压后得到jar包放到%JAVA_HOME%\lib下,并且将其添加到ClassPath系统环境变量中。

然后使用sqlite,但是import org.sqlite.JDBC;出错,为什么呢

以下为代码:
import java.sql.*;
import org.sqlite.JDBC;
public class TestSQLite{
     public static void main(String[] args){
        try{
         Class.forName("org.sqlite.JDBC");        
         Connection conn = DriverManager.getConnection("jdbc:sqlite:zieckey.db");        
         Statement stat = conn.createStatement();
         stat.executeUpdate( "create table tbl1(name varchar(20), org.hibernate.QueryException: could not resolve property, 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', java.lang.NoClassDefFoundError: javax/servlet/http/,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 ( );
         }
    }
}


无满意答案

------解决方案--------------------------------------------------------
可参考:
CGI怎么连接SQLite   http://www.myexception.cn/cgi/206265.html


相关的主题文章:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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"); //

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值