英文:
sqlite not found in Netbeans Java
问题
我正在使用Netbeans 16和Java 19.0.2在Windows 11上。
当我尝试访问一个新的sqlite文件时,我遇到了以下错误:
java.lang.ClassNotFoundException: org.sqlite.JDBC
这是我的代码部分:
package com.thompco.propertymanager.table;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Database {
String filename;
Connection connection;
public Database(String filename) throws ClassNotFoundException {
this.filename = filename;
connect();
}
public final void connect() throws ClassNotFoundException {
try {
Class.forName("org.sqlite.JDBC");
String url = String.format("jdbc:sqlite:%s", filename);
connection = DriverManager.getConnection(url);
System.out.println("连接到SQLite已建立。");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
public static void main(String[] args) {
try {
Database database = new Database("newFile.sqlite");
database.connect();
database.createTransactionTable();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
我认为我已将sqlite的jar文件添加到我的路径中。
我尝试将它添加到文件的顶部。
英文:
I am using Netbeans 16 and Java 19.0.2 on Windows 11.
I am getting:
java.lang.ClassNotFoundException: org.sqlite.JDBC
when I try to access a new sqlite file:
package com.thompco.propertymanager.table;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Database {
String filename;
Connection connection;
public Database(String filename) throws ClassNotFoundException {
this.filename = filename;
connect();
}
public final void connect() throws ClassNotFoundException {
try {
Class.forName("org.sqlite.JDBC");
String url = String.format("jdbc:sqlite:%s", filename);
connection = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (connection != null) {
connection.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
public static void main(String[] args) {
try {
Database database = new Database("newFile.sqlite");
database.connect();
database.createTransactionTable();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
答案1
得分: 1
看起来你已经将sqlite jar文件添加到库"Absolute Layout"的jar列表中。
现在,你仍需要确保在你的项目中添加了这个库(这是在你可以导入源代码中的类之前的先决条件)。
提示:
- 你很可能应该将sqlite添加为一个独立的库。
- 更建议使用Maven构建系统,并在pom.xml中指定依赖项。这样可以进行版本控制,并且Maven会代表你下载库文件。
英文:
It looks like you added the sqlite jar to the list of jars for the library Absolute Layout
.
Now you still need to make sure that this library is added to your project (a prerequisite before you can import the classes in your source code).
Hints:
- You likely should have added sqlite as a separate library.
- It would be more advisable to use the Maven build system and specify dependencies in pom.xml. That one can be version controlled. And Maven will download the libraries on your behalf.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论