Java - SQLite 连接(找不到适用于 JDBC:sqlite:main.db 的驱动程序)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43161060/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java - SQLite connection (No suitable driver found for JDBC:sqlite:main.db)
提问by Jakub Gadawski
I have problem with SQLite connection on my Java project. Error looks like this :
我的 Java 项目上的 SQLite 连接有问题。错误如下所示:
No suitable driver found for JDBC:sqlite:main.db
找不到适合 JDBC:sqlite:main.db 的驱动程序
That's my code:
那是我的代码:
public static void main(String[] args) {
Connection c = null;
try {
// Class.forName("org.sqlite.JDBC");
String url = "JDBC:sqlite:main.db";
c = DriverManager.getConnection(url);
System.out.println("Connection to sql");
} catch ( SQLException e ) {
System.err.println( e.getMessage() );
} finally {
try{
if( c!= null ) {
c.close();
}
}catch( SQLException ex )
{
System.out.println(ex.getMessage());
}
}
}
Can You help me please?
你能帮我吗?
回答by Babatunde Adeyemi
If you're using maven, ensure that the scope
isn't specified as test.i.e.
如果您使用的是 maven,请确保scope
未将其指定为 test.ie
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.18.0</version>
</dependency>
回答by duffymo
回答by Anant666
I think you have not added the SQLITE JDBC driver to your classpath. Just download the jar FROM HEREand add it to your classpath. Your error would be resolved.
我认为您还没有将 SQLITE JDBC 驱动程序添加到您的类路径中。只需从这里下载 jar并将其添加到您的类路径中。您的错误将得到解决。
You should also have a look on This answerand This resource. By reading both of them you will learn more about SQLITE as well as how to make a connection with JDBC.