b.在用户DSN选项卡中点击加入,选择Driver do Microsoft Excel(*.xls)
注冊好数据源后就能够写代码了,一个示比例如以下:
public class ExcelReader {
private String entry;//ODBC数据源名称
public ExcelReader(String entry) {
this.entry = entry;
}
//sheetName为工作表名称
public String read(String sheetName) throws Exception {
StringBuilder builder = new StringBuilder();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection connection = DriverManager.getConnection("jdbc:odbc:" + entry);
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from [" + sheetName + "$]");
while(rs.next()) {
builder.append(rs.getObject(1));//示意性仅仅读取一列
}
rs.close();
statement.close();
connection.close();
return builder.toString();
}
public static void main(String[] args) throws Exception {
ExcelReader reader = new ExcelReader("etl");
System.out.println(reader.read("test"));
}
}
原文:http://www.cnblogs.com/brucemengbm/p/6941963.html