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
然后运行我的代码......错误在哪里?
答案 0 :(得分:0)
JDBC-ODBC Bridge已过时,已从Java 8中删除。如果您需要操作Excel文档而您无法(或不愿意)将您的环境降级到Java 7,那么您可能需要调查{{3 }}