- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个程序来读取数据库并输出它。我已按照 http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java 上的教程进行操作。但是当我运行我的程序时,什么也没有发生。甚至没有错误...
我可能错过了一些东西,但我不知道它可能是什么。这是我的代码:
import java.sql.*;
public class ReadDB {
public static void ReadDB() {
try{
//Source: http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from-Java
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=ratingdb.accdb;";
Connection conn = DriverManager.getConnection(database, "", "");
Statement s = conn.createStatement();
//Read Table
String selTable = "SELECT * FROM RATINGS";
s.execute(selTable);
ResultSet rs = s.getResultSet();
while((rs!=null) && (rs.next()))
{
System.out.println(rs.getString(1) + " : " + rs.getString(2));
}
s.close();
conn.close();
} catch(Exception e){
System.out.println ("Unable to connect to the database");
System.out.println ("Exception: " + e.getMessage());
}
}
}在黑豹发表评论后,我得到了这个错误:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]一般错误无法打开进程 0x13f4 线程 0x1204 DBC 0x42170d4 的临时( volatile )Ace DSN 注册表项
编辑:发生新错误:异常:[Microsoft][ODBC Microsoft Access Driver]不是有效的文件名。
这是否意味着我使用的驱动程序不存在?
最佳答案
即使它抛出异常,您也无法看到它们,因为您以错误的方式处理了错误。您不应该只是捕获异常并继续前进。这违背了异常处理的整个概念。
您应该执行类似的操作,以便在控制台中打印异常。
try {
//code that throws exceptions
} catch(Exception e) {
e.printStackTrace(); //prints the error to the console and you missed it
}
编辑:您似乎遇到了一些权限问题。
网站摘录 http://support.sas.com/kb/40/228.html
This problem occurs for several reasons, including not having permissions on an ODBC registry key. In such a case, change the permissions on the registry key as follows:
Start the registry editor using the regedit command: select Start ► Run and enter regedit.
If your SAS PC Files Server is on a 64-bit machine, expand the following key: HKEY_LOCAL_MACHINE ► SOFTWARE ► WOW6432NODE ► ODBC.
If your SAS PC Files Server is on a 32-bit machine, expand the following key: HKEY_LOCAL_MACHINE ► SOFTWARE ► ODBC.
Right-click the ODBC folder and select Permissions.
Make sure that the logon ID that is running the SAS process has full control. The problem might also occur due to older ODBC drivers from Microsoft, particularly from Office 2007. To install the newer ODBC drivers, go to Microsoft Access Database Engine 2010 Redistributable.
If you have 32-bit Microsoft Office, download the AccessDatabaseEngine.exe file. Download the other ODBC driver only if you have 64-bit version of Microsoft Office.
如果您尝试创建 .mdb
文件并使用它,请执行此操作
前往文件 -> 选项 -> 常规,并将默认文件格式设置为 Access 2002-2003
并将数据库 URL 更改为
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=ratingdb.mdb;";
使用.mdb
文件。
要使用 .accdb
文件,请尝试执行此操作,
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=ratingdb.accdb;";
关于java - 读取 .accdb 数据库时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23563005/
我正在尝试将 accdb 文件从 Access 2010 中的使用转换为 Access 2007。我首先尝试使用 Access 2007 打开该文件,但出现错误 Unrecognized databa
我正在处理 Excel VBA 宏,并且想要从 MS Access 数据库(.accdb 文件)检索数据。 我尝试使用下面的连接字符串,它抛出运行时错误“438” Dim cn As Objec
我正在尝试创建一个程序来读取数据库并输出它。我已按照 http://www.codeproject.com/Articles/35018/Access-MS-Access-Databases-from
我最近将数据库从 .mdb (MS Access 2003) 更新为 .accdb (MS Access 2010)。 通过这次更新,我还将我的提供程序从:Microsoft.Jet.OLEDB.4.
我上这门课已经几天了,现在正在网上搜索以寻找解决方案。我在这里尝试做的是连接到扩展名为 .accdb 的 Access 2010 数据库 我已经成功连接到扩展名为 .mdb 但不是 的旧数据库>.ac
我一直在寻找打开 .accdb 数据库并从此文件读取/写入日期的解决方案。该文件保存在本地而不是服务器上,该解决方案无需额外的库即可运行。 有人可以帮助我吗? 谢谢你的建议 最佳答案 我的建议是使用
我问了两个类似的问题: Use OLEDB to read AccessFile from Stream to DataSet Read Microsoft Access File(.accdb) b
我正在尝试创建一个使用Access 2007 DB(.accdb)的MVC应用程序。我可以使用DataSet创建模型。但是,如果我尝试使用EntityFramework创建模型,那么我无法摆脱VS20
我想我的问题会被认为是愚蠢的,但我真的被困住了。 如何查看 *.accdb 文件中的所有表? 我使用 Office 14 中的 Microsoft Access 打开和编辑该文件。然后我去Databa
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我正在使用 Visual Studio Community 2017 Access 2010 - 2016 年 我可以导入我创建的 Access 文件 从客户端发送的文件包含(表、查询、表单、宏和模块
使用下面的代码,当找不到运行提供程序时,我收到以下错误,下面的代码是从网上复制和编辑的,它以前使用.mdb文件,但我尝试将其更改为.accdb,因为这是我的格式需要它。我正在尝试制作一个宏,在运行时将
我使用 .accdb 文件作为 Java 桌面应用程序的数据库。该文件用作数据库,但我也可以打开它并查看所有数据,我也可以更改它而不使用该程序。有什么方法可以阻止该文件并且用户无法直接使用 Acces
我使用的是 MS Office 2010。我想创建一个 .mdb 数据库。我环顾四周,但不知道如何更改默认扩展名。 该数据库将用于练习 Java JDBC-ODBC 连接,为此我需要一个 .mdb 数
我不明白为什么我的代码无法保存到我的 .accdb 数据库中。 我正在从 .accdb 数据库文件中获取数据并将其显示在 DataGridView 中,然后允许对其进行更改。 (这是一个库存控制系统。
如果我有一个基本的 windows xp 系统、ruby 和一个 ms access 2007 文件(例如 c:/foo/bar.accdb)文件,读取该 .accdb 文件的侵入性最小的方法是什么。
我试图将 Access 数据库的大小保持在最低限度,并且需要删除以前使用但现在不需要的几个大图像。我的理解是 Access 文件 (.accdb) 将图像存储在数据库中。你知道是否可以删除它以及如何删
这两个扩展有什么区别? 我需要使用 ADODB 连接从 WORD 文件写入 Access 数据库 当我创建一个新的 Access 数据库时,它让我可以选择只制作一个 ACCDB 文件,而由于某种原因我
我有一个这样的文件: strPath = "S:\HR\Forms\forms_database.accdb" 我通过 WORD adodb.connection 连接到它 我的数据库应该是不同的扩展
我尝试自动创建 .accdb 数据库,但使用 create() 函数时出现编译错误: 我使用这个答案中的代码: Create an Access database file (.mdb or .acc
我是一名优秀的程序员,十分优秀!