sqlite not found in Netbeans Java

huangapple go评论45阅读模式
英文:

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

I (think) I have added the sqlite jar to my path:
sqlite not found in Netbeans Java

I tried to add it at the top of my file:
sqlite not found in Netbeans Java

答案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.

huangapple
  • 本文由 发表于 2023年2月8日 19:06:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75384877.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定