gpt4 book ai didi

java - 尝试使用 Jackcess 和 JDBC 时抛出异常

转载 作者:行者123 更新时间:2023-11-30 08:13:10 25 4
gpt4 key购买 nike

在听取了这里有用的用户的建议后,我对我的代码进行了一些更改。 让这个驱动程序加载我缺少什么?有人建议我购买 Jackcess,我已将其收录在我的图书馆中。我正在使用 java 8 我没有过去

Connection conn = DriverManager.getConnection(database, "", ""); 

在它抛出一堆异常之前。

import java.sql.*;
import javax.swing.JOptionPane;
import java.sql.DriverManager;
private void SubmitActionPerformed(java.awt.event.ActionEvent evt) {

try {
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=db1.mdb;";
Connection conn = DriverManager.getConnection(database, "", "");
//String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
//Class.forName(driver);
// String db = "jdbc:odbc:db1";
//con = DriverManager.getConnection(db);
st = conn.createStatement();
System.out.println("it actually ready this set of code!");
String un = UserName.getText().trim();
String pw = Password.getText().trim();
String sql = "select user,pass from Table2 where user='"+un+"'and pass='"+pw+"'";
rs=st.executeQuery(sql);
int count = 0;
while(rs.next()){
count = count+1;
}
if (count==1){
JOptionPane.showMessageDialog(null,"User, Found Access Granted!");
}
else if (count>1){
JOptionPane.showMessageDialog(null,"Duplicate User, Access Denied!");
}
else {
JOptionPane.showMessageDialog(null, "user doesn't exsist. ");
}

} catch (Exception ex){
System.out.println("exception 2, " );
ex.printStackTrace();
}

// TODO add your handling code here:
}

这些是我得到的异常错误:

exception 2, 
java.sql.SQLException: No suitable driver found for jdbc:odbc:Driver= {Microsoft Access Driver (*.mdb)};DBQ=db1.mdb;
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at cdeventplanner.CdEventPlannerLogin.SubmitActionPerformed(CdEventPlannerLogin.java:118)
at cdeventplanner.CdEventPlannerLogin.access$100(CdEventPlannerLogin.java:14)
at cdeventplanner.CdEventPlannerLogin$2.actionPerformed(CdEventPlannerLogin.java:67)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2750)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

最佳答案

您正在尝试使用 JDBC 访问数据库。根据Jackcess FAQ ,Jackcess 驱动程序不支持 JDBC:

Does Jackcess provide a JDBC driver for Microsoft Access databases?

Unfortunately, no. The Jackcess API is a direct implementation of the features available for interacting with an Access database. There is currently no implementation of the JDBC API included with the Jackcess library. While this library would be a great foundation for a JDBC driver, implementing the JDBC API is currently outside the scope of this project. There have been a few attempts to use Jackcess to build JDBC drivers for Access databases, but most of the projects have not progressed very far before becoming inactive. The UCanAccess project, however, is a currently active open source project which provides a JDBC driver built on top of Jackcess.

有关如何使用 Jackcess 的专有 DB API 的更多信息可用 here .

关于java - 尝试使用 Jackcess 和 JDBC 时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30108886/

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