---
title: "通过JDBC-ODBC桥接器访问Excel电子表格"
author: "prodream"
date: "2008-08-23T16:28:00Z"
tags: []
slug: "jdbc-odbc-excel"
draft: false
lastmod: "2008-08-23T16:28:00Z"
id: 578034
url: "https://prodream.iteye.com/blog/578034"
---

通过JDBC-ODBC桥接器访问Excel电子表格

1.设置数据源  
Excel数据源选择的驱动程序是Microsoft Excel Driver

2.选择表  
与访问其他数据库不同的是，我们必须在电子表格中选出一工作区作为连接时使用的表。  
在Excel电子表格中拖动鼠标选出范围，然后在Excel菜单中选择"插入-&gt;名称-&gt;定义"给选中的工作区命名（这以工作区的名称将作为连接时使用的表名).

3.加载数据源，连接Excel  
try{  
//加载驱动  
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
}  
catch(ClassNotFoundException e){}  
try{  
//连接Excel的表excel\_form\_name  
Connection con=DriverManager.getConnection("jdbc:odbc:excel\_form\_name","","");  
Statement sql=con.createStatement();  
ResultSet rs=sql.executeQuery("select * from 名字");  
//处理结构集 ...  
}  
catch(SQLException e1){}