java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver

出现这个异常的原因在于从JDK1.8开始,Oracle删除了jdbc-odbc桥,如果你要使用jdbc-odbc桥,那么请下载jdk1.7或者更低版本

近期笔者经常收到百度知道的消息,都是关于这个的一些评论,所以发一篇再博文说明下。

官网对jdbc-odbc驱动的说明:http://docs.oracle.com/javase/7/docs/technotes/guides/jdbc/bridge.html

JDBC-ODBC Bridge

The JDBC-ODBC Bridge allows applications written in the Java programming language to use the JDBC API with many existing ODBC drivers. The Bridge is itself a driver based on JDBC technology ("JDBC driver") that is defined in the class sun.jdbc.odbc.JdbcOdbcDriver. The Bridge defines the JDBC sub-protocol odbc.

Status of the JDBC-ODBC Bridge

The JDBC-ODBC Bridge should be considered a transitional solution; it will be removed in JDK 8. In addition, Oracle does not support the JDBC-ODBC Bridge. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.

Why use ODBC at all?

The ideal is "Pure Java": no native code, no platform dependentfeatures. But you may need to begin your development effort rightaway, without waiting for your DBMS to offer a Java-only JDBCdriver. Partly native drivers, such as the JDBC-ODBC Bridge, letyou create programs that easily adapt to Pure Java drivers as theybecome available.

早期的时候java刚诞生没多久,jdbc还不是很成熟,为了保持对微软的驱动兼容使用了jdbc-odbc最为过渡,现在,jdbc已经可以独挡一面了,所以oracle/sun删除了这个驱动,这很正常。但是由于大多数教材的编者并没有与时俱进,操作数据库的第一个例子在jdk1.7的时候仍然是jdbc-odbc......,大部分编者认为配置微软的东西比配置mysql简单,实际上对初学者来说基本没有什么区别。

Oracle/sun还说了,以sun开头的包以后有废弃的风险,如果项目以后要更新的话,建议还是尽量避开这些包

你可能感兴趣的:(jdk,oracle,jdbc,sun,odbc)