在Java中注册Sqlite驱动程序的问题 [英] Issues registering Sqlite driver in Java

查看:54
本文介绍了在Java中注册Sqlite驱动程序的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Java连接到sqlite数据库.我在Windows中编程.我下载了sqlite驱动程序,并在Windows环境变量中设置了类路径.调用此代码时,我收到classNotFoundException:

I am trying to connect to a sqlite database from Java. I am programming in Windows. I downloaded the sqlite driver and set the classpath in the windows environment variables. I get a classNotFoundException when this code is called:

   Class.forName(sDriver);  

其中sDriver是"org.sqlite.JDBC".这是来自异常的堆栈跟踪:

where sDriver is "org.sqlite.JDBC" Here is the stacktrace from the exception:

java.lang.ClassNotFoundException: org.sqlite.JDBC
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at com.ib.client.examples.Mydb.setConnection(Mydb.java:49)
at com.ib.client.examples.Mydb.init(Mydb.java:33)
at com.ib.client.examples.Mydb.<init>(Mydb.java:17)
at com.ib.client.examples.Example1.run(Example1.java:40)

任何帮助将不胜感激.谢谢.

Any help would be greatly appreciated. Thanks.

推荐答案

我不知道您要使用哪个JDBC驱动程序,但是到目前为止,我发现的最好的SQLite JDBC驱动程序是Xerial Project制造的: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

I don't know which JDBC driver you are trying to use, but the best SQLite JDBC driver i found so far is the one made by the Xerial Project: http://www.xerial.org/trac/Xerial/wiki/SQLiteJDBC

您可以在这里找到驱动程序的最新版本: http://www.xerial.org/maven/repository/snapshot/org/xerial/sqlite-jdbc/3.7.8-SNAPSHOT/

You can find the latest version of the driver here: http://www.xerial.org/maven/repository/snapshot/org/xerial/sqlite-jdbc/3.7.8-SNAPSHOT/

它使用适用于Windows(32位和64位),Linux(32位和64位)和MacOS(32位和64位)的本机驱动程序,并且在不受支持的平台的情况下使用纯Java实现.

It uses a native driver for Windows (32 and 64 bits), Linux (32 and 64 bits) and MacOS (32 and 64 bits), and falls back to a pure java implementation in the case of an unsupported platform.

所有本机库(dll等)都包含在驱动程序的JAR文件中,您不必担心加载其中的任何一个.它将自动为您检测正确的库.

All native libraries (dll, so, etc) are included in the driver's JAR file, and you don't need to worry about loading any of them. It will autodetect the right library for you.

如果尝试从命令行运行程序,则必须在类路径中指定每个jar文件.在classpath环境变量中设置它们的路径是不够的.

If you are trying to run your program from command line, you must specify every jar file in the classpath. Setting their path in the classpath environment variable is not enough.

示例:

java YourProgram -cp classes;lib/sqlite.jar;c:\libs\java\lib1.jar

这篇关于在Java中注册Sqlite驱动程序的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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