gpt4 book ai didi

java - 尝试连接 UCanAccess 时出现 "No suitable driver found"错误

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:30 27 4
gpt4 key购买 nike

我根据这篇文章修改了以下代码回答:

Manipulating an Access database from Java without ODBC

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class Main {

void reportTotalCopies(Connection connection)
{
try{
Statement statement1 = connection.createStatement();
Statement statement2 = connection.createStatement();
String Sql = "SELECT [Κωδικός], [Τίτλος], [Πλήθος Αντιγράφων] FROM [Βιβλίο] ";

ResultSet set1 = statement1.executeQuery(Sql);
while (set1.next())
{
int code = set1.getInt(1);
String title = set1.getString(2);
int copies = set1.getInt(3);
Sql = "SELECT COUNT(Δανεισμός."
+ "[Αριθμός Ταυτότητας Μέλους]) "
+ "AS [Δανεισμένα] "
+ "FROM Δανεισμός "
+ "WHERE Δανεισμός.[Κωδικός Βιβλίου] = "
+ code
+ " GROUP BY Δανεισμός.[Κωδικός Βιβλίου]";
ResultSet set2 = statement2.executeQuery(Sql);
if (set2.next())
copies += set2.getInt(1);
System.out.printf("%-60s%d\n", title, copies);
}
}
catch(SQLException ex){
while(ex != null){
ex.getMessage();
ex.getNextException();

}
}
}

public static void main(String args[]) {


try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
//String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + filename + ";DriverID=22;READONLY=true}";
String database = "jdbc:ucanaccess:\"Library.accdb\"";
Connection con = DriverManager.getConnection("jdbc:ucanaccess:C:\\JavaBooks\\Java12\\Library.mdb");
new Main().reportTotalCopies(con);
//new Java1202().reportBooksByMember(connection);
con.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Here");
}
}
}

我在运行它时收到以下错误...

java.sql.SQLException: No suitable driver found for jdbc:ucanaccess:C:\JavaBooks\Java12\Library.mdb
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Main.main(Main.java:52)

我还在 Eclipse 构建路径中包含了 UCanAccess 的 5 个 JAR 文件。

可能导致问题的原因是什么?

最佳答案

jdbc url 错误,你丢了一个//

jdbc:ucanaccess://C:\JavaBooks\Java12\Library.mdb

关于java - 尝试连接 UCanAccess 时出现 "No suitable driver found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30793130/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com