[英]How do I establish a connection from my java program to sqlite3? Package error when attempting
When I try to connect to my database;当我尝试连接到我的数据库时; it throws me these error:
它向我抛出这些错误:
PersonTidbok.java:3: error: package org.sqlite does not exist
import org.sqlite.SQLiteConfig;
^
PersonTidbok.java:18: error: cannot find symbol
SQLiteConfig config = new SQLiteConfig();
^
symbol: class SQLiteConfig
location: class PersonTidbok
PersonTidbok.java:18: error: cannot find symbol
SQLiteConfig config = new SQLiteConfig();
^
symbol: class SQLiteConfig
location: class PersonTidbok
3 errors
From the following code:从以下代码:
import java.io.*;
import java.sql.*;
import org.sqlite.SQLiteConfig;
public class PersonTidbok {
public static final String DB_URL = "jdbc:sqlite:C:/Users/zeren/SQlite/slutuppgift";
public static final String DRIVER = "org.sqlite.JDBC";
public static void main(String[] args) throws IOException {
Connection conn = null;
try {
Class.forName(DRIVER);
SQLiteConfig config = new SQLiteConfig();
config.enforceForeignKeys(true);
conn = DriverManager.getConnection(DB_URL,config.toProperties());
} catch (Exception e) {
System.out.println( e.toString() );
System.exit(0);
}
}
}
The code was given from my teacher for our final assigment, and im wondering why he'd include a package that doesnt exist somehow?代码是我老师为我们的最终作业提供的,我想知道他为什么要包含一个不知何故不存在的包? How doesnt package org.sqlite not exist?
org.sqlite 包怎么不存在? I dont get it, someone help me" :C
我不明白,有人帮帮我”:C
SQLiteConfig is a class which is an integral part of the sqlite-jdbc-3.xxjar JDBC driver JAR file. SQLiteConfig是一个类,它是sqlite-jdbc-3.xxjar JDBC 驱动程序 JAR 文件的一个组成部分。 If this is failing then obviously you driver jar file can not be found within the classpath.
如果这失败了,那么显然在类路径中找不到驱动程序 jar 文件。 Be sure to add the
sqlite-jdbc-3.xxjar
file to your project.确保将
sqlite-jdbc-3.xxjar
文件添加到您的项目中。
If in Netbeans:如果在 Netbeans 中:
I can't help you with other IDE's since I simply don't use them.我无法帮助您使用其他 IDE,因为我根本不使用它们。
The code you provided works for me.您提供的代码对我有用。 Because you have managed to import org.sqlite.SQLiteConfig basically tells me that you do have the driver included within your project but , since the code was given by your teacher then a copy/paste would account for the import but its validity would be highlighted (or underlined) in some fashion via the IDE indicating an error.
因为您已成功导入org.sqlite.SQLiteConfig基本上告诉我您的项目中确实包含驱动程序,但是,由于代码是您的老师提供的,因此复制/粘贴将解释导入,但其有效性将被突出显示(或下划线)以某种方式通过 IDE 指示错误。
在 jGRASP 中,使用“设置”>“路径/类路径”>“工作区”(或项目)然后使用“类路径”选项卡将 jar 文件添加到类路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.