【发布时间】:2015-12-24 09:00:36
【问题描述】:
我使用net.ucanaccess.jdbc.UcanaccessDriver 从 MS Access 读取数据:
public static void main(String[] args) {
try {
Statement statement = getConnection().createStatement();
ResultSet resultSet = statement.executeQuery(" select * from students ");
while (resultSet.next()) {
String log = resultSet.getLong("id") + " - " + resultSet.getString("name") + " - " + resultSet.getString("family");
System.out.println(log);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
public static Connection getConnection() {
Connection connection = null;
try {
File f = new File("files/access.accdb");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
connection = DriverManager.getConnection("jdbc:ucanaccess://" + f.getAbsolutePath());
}
catch (Exception e) {
e.printStackTrace();
}
return connection;
}
但现在,我想以InputStream 的身份从 MS Access 读取数据,可能是这样的:
public static Connection getConnection() {
Connection connection = null;
try {
File f = new File("files/access.accdb");
InputStream inputStream = new FileInputStream(f);
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
connection = DriverManager.getConnection(inputStream); /*Changed*/
}
catch (Exception e) {
e.printStackTrace();
}
return connection;
}
【问题讨论】:
-
这根本不可能。
-
为什么选择@wero?你能提供一些技术信息吗?
-
InputStream可用于一次性阅读内容。应该如何在它之上实现 JDBC 驱动程序?因此,UcanaccessDriver 需要 mdb 文件来读取、写入或锁定... -
为什么要使用 InputStream?
-
在我的 web 项目中,一个用户上传了一个 MS Access 文件,我将它作为 blob 保存到 oracle 数据库中,所以另一个用户登录到系统然后想查看并存储上传文件的数据进入oracle数据库的另一个表,并且可能想要编辑新记录。
标签: java ms-access jdbc inputstream ucanaccess