环境描述
win7 64位 Eclipse开发java ,该段程序是连接access数据库,数据源是stu.mdb
出错代码段
public Statement getConnection()
{
Connection con=null;
Statement stm=null;
String dburl="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=F:\\stu.mdb";
//64位下需安装access2010 64位版,否则报错java.sql.SQLException: [Microsoft][ODBC 统统程序管理器]
//F:\\是我放置数据源文件stu.mdb的目录
//32位下用String dburl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=F:\\stu.mdb";
try
{
String username="";
String password="";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //反射机制,调用jdbc-odbc驱动
con=DriverManager.getConnection(dburl,username,password); //数据库建立连接
stm = con.createStatement();
}
catch(SQLException e){JOptionPane.showMessageDialog(null,e.getMessage(), "出错",JOptionPane.ERROR_MESSAGE);}
// System.out.println(e.getMessage());
catch(ClassNotFoundException ex){JOptionPane.showMessageDialog(null,ex.getMessage(), "出错",JOptionPane.ERROR_MESSAGE);}
//System.out.println(ex.getMessage());
return stm;
}
报错如下
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: sun/security/action/LoadLibraryAction
at sun.jdbc.odbc.JdbcOdbc.(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at DBconnection.getConnection(DBconnection.java:29)
at login$1.actionPerformed(SimsLogin.java:95) ……
最新版本jdk,sun.security.action中没有 LoadLibraryAction.class,要到哪里去找这个类呢?另外这个类是怎么用到的呢?