import java.sql.Connection;
import java.sql.DriverManager;
public class ConnectionExample {
public static void main(String args[]) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (Exception e) {
System.out.println("JDBC-ODBC driver failed to load.");
return;
}
try {
Connection con = DriverManager.getConnection("jdbc:odbc:abcdefg", "", "");
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}这段代码总是打印
"JDBC-ODBC driver failed to load."
我不明白问题出在哪里。我遵循以下步骤:
转到c:\windows\sysWOW64\odbcad32.exe
system dsn tab - add -> Microsoft Excel Driver (*xls, *xlsx, *xlsm, *xlsb)
给数据源命名abcdefg
Select Workbook -> go to myFile excel path and add it -> OK
然后运行我的代码..。哪里出错了?
发布于 2015-06-04 11:27:03
JDBC已经过时,已经从Java 8中删除了。如果您需要操作一个Excel文档,并且您无法(或不愿意)将您的环境降级为Java 7,那么您可能需要研究阿帕奇POI。
https://stackoverflow.com/questions/30641465
复制相似问题