使用 jdbc 连接到 Excel 表而不指定 DSN 到 Excel 表 [英] Connecting to excel sheet using jdbc without specifying DSN to Excel sheet

查看:15
本文介绍了使用 jdbc 连接到 Excel 表而不指定 DSN 到 Excel 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 jdbc 或其他一些方法连接到 Excel 工作表,但我不想使用管理工具为其指定 DSN.他们是否有办法使用代码来做到这一点?如果是,如何?

I want to connect to an excel sheet using jdbc or some other method but i do not want to specify DSN for the same using administrative tool. Is their someway to do it using code? If yes how ?

提前致谢

推荐答案

还可以在不使用 DSN 的情况下连接到电子表格,这提供了一种更灵活的代码方式,无需访问即可在代码中将 JDBC 指向感兴趣的 Excel 文件到客户端注册表以定义所需的 DSN.没有DSN,db连接创建如下,请注意构造JDBC URL的区别:

It is also possible to connect to a spreadsheet without using DSN, which provides a more flexible way within code to point JDBC at an Excel file of interest without the accesses to a client registry to define the required DSN. Without DSN, the db connection is created as following, please not the difference of constructed JDBC URL:

java.sql.DriverManager.getConnection( "jdbc:odbc:Driver={Microsoft Excel Driver
(*.xls)};DBQ=C:/Documents and Settings/myPath/Desktop/qa.xls");

此处 DBQ 定义了目标电子表格文件 (qa.xls) 的路径.反斜杠和正斜杠都可以正常工作.

Here DBQ defines the path to the target spreadsheet file (qa.xls). Both backslash and forward slash work well.

来源:可用来源

这篇关于使用 jdbc 连接到 Excel 表而不指定 DSN 到 Excel 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆