java.lang.ClassNotFoundException:来自xerial的Sample.java程序中的org.sqlite.JDBC错误 [英] java.lang.ClassNotFoundException: org.sqlite.JDBC error in Sample.java program from xerial

查看:320
本文介绍了java.lang.ClassNotFoundException:来自xerial的Sample.java程序中的org.sqlite.JDBC错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Xerial的Sample类在Eclipse中使用sqlite,但我一直收到错误ClassNotFoundException:org.sqlite.JDBC



我下载了 https://bitbucket.org/xerial/sqlite-jdbc/downloads <中的sqlite-jdbc-3.7.2.jar文件/ A>。将它复制到eclipse中我的项目database_test下的lib文件夹中。然后右键单击Project-> Properties-> Java Build Path-> Libraries选项卡 - > Add JARs->选择jar文件。我试图从这里找到的Xerial执行此代码: https://bitbucket.org/xerial/sqlite- jdbc#markdown-header-usage

  //使用当前的类加载器加载sqlite-JDBC驱动程序
Class.forName(org.sqlite.JDBC);

连接连接= null;
try
{
//创建数据库连接
connection = DriverManager.getConnection(jdbc:sqlite:sample.db);
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); //将超时设置为30秒。

statement.executeUpdate(drop table if exists person);
statement.executeUpdate(create table person(id integer,name string));
statement.executeUpdate(插入人值(1,'leo'));
statement.executeUpdate(insert into person values(2,'yui'));
ResultSet rs = statement.executeQuery(select * from person);
while(rs.next())
{
//读取结果集
System.out.println(name =+ rs.getString(name) );
System.out.println(id =+ rs.getInt(id));
}
}
catch(SQLException e)
{
//如果错误消息是内存不足,
//这可能意味着找不到数据库文件
System.err.println(e.getMessage());
}
最后
{
尝试
{
if(connection!= null)
connection.close();
}
catch(SQLException e)
{
//连接关闭失败。
System.err.println(e);
}
}

}
}



我去过的每个网站都说过将jar文件添加到你的构建路径或类路径中,我相信我已经做到了,但没有解决问题。任何帮助,将不胜感激。谢谢。

解决方案

感谢用户phew的帮助/想法。



<我错过了Xerial网站上针对Sample程序的明显命令行指令。要使程序从命令行运行,我必须将JAR文件复制到与.java程序相同的文件夹中。然后运行以下命令:



java -classpath。:sqlite-jdbc-(VERSION).jarSample


I am trying to get Xerial's Sample class to work in Eclipse with sqlite, but I keep getting the error "ClassNotFoundException: org.sqlite.JDBC"

I downloaded the sqlite-jdbc-3.7.2.jar file from https://bitbucket.org/xerial/sqlite-jdbc/downloads. Copied it into the lib folder under my project "database_test" in eclipse. Then right-clicked on the Project->Properties->Java Build Path->Libraries Tab->Add JARs->Select the jar file. I am trying to execute this code from Xerial found here: https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage

// 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);
  }
}

} }

Every site I have been to has said add the jar file to your build path or class path and I believe I have done that, but nothing has solved the problem. Any help would be appreciated. Thanks.

解决方案

Thanks to user phew for the help/ideas.

I missed the obvious command line instructions on Xerial's site for the Sample program. To get the program to run from the command line, I had to copy the JAR file into the same folder as the .java program. Then run the following command:

java -classpath ".:sqlite-jdbc-(VERSION).jar" Sample

这篇关于java.lang.ClassNotFoundException:来自xerial的Sample.java程序中的org.sqlite.JDBC错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆