使用jdbc连接到excel表,而不指定DSN到Excel表 [英] Connecting to excel sheet using jdbc without specifying DSN to Excel sheet
问题描述
我想使用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,这在代码中提供了更灵活的方式来指向感兴趣的Excel文件中的JDBC,而无需访问客户端注册表来定义所需的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屋!