如何修复“ classNotFoundException”?

时间:2019-06-11 19:14:39

标签: java ucanaccess

我一直试图连接到mdb / accdb数据库。但是我没有IDE(我更喜欢这个)

J:\RR>javac -classpath ".;J:\RR\UCanAccess-4.0.4-bin\ucanaccess-4.0.4.jar; J:\RR\UCanAccess-4.0.4-bin\lib\*" *.java

这是我运行树时收到的信息

J:\RR\
|   compile.bat
|   Continent.class
|   Continent.java
|   Country.class
|   Country.java
|   jackcess-3.0.1.jar
|   Main.class
|   Main.java
|   RISKI.accdb
|   RISKI.mdb
|
\---UCanAccess-4.0.4-bin
    |   console.bat
    |   console.sh
    |   copyright.txt
    |   ucanaccess-4.0.4.jar
    |   version.txt
    |
    +---lib
    |       commons-lang-2.6.jar
    |       commons-logging-1.1.3.jar
    |       hsqldb.jar
    |       jackcess-2.1.11.jar
    |
    +---licenses
    |       apache-license-2.0.txt
    |       hsqldb_lic.txt
    |       hypersonic_lic.txt
    |       lgpl-2.1.txt
    |       licenses.txt
    |
    \---loader
            ucanload.jar

我尝试用所有可以看到的方式更改类路径

import java.sql.*;
import java.lang.ClassNotFoundException;
public class Main{

public static void main(String [ ] args)throws ClassNotFoundException, SQLException 
    {
        Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
        try{

            Connection conn=DriverManager.getConnection(
                "jdbc:ucanaccess://J:\\Risk_Ripoff\\RISKI.accdb");
            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("SELECT [LastName] FROM [Clients]");
            while (rs.next()) {
                System.out.println(rs.getString(1));
            }
        }
        catch(Exception ee){ System.out.println(ee);}
    }
}

我想从数据库中选择信息,但发现此错误:

J:\RR>java Main
Exception in thread "main" java.lang.ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at Main.main(Main.java:7)

1 个答案:

答案 0 :(得分:0)

也许在运行命令时设置类路径:

java -classpath ".;J:\RR\UCanAccess-4.0.4-bin\ucanaccess-4.0.4.jar; J:\RR\UCanAccess-4.0.4-bin\lib\*" Main