如何避免java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序]找不到文件'(unkown)'
问题描述:
在Windows 7上的java se和microsoft access/jet数据库上。在使用Windows 7之前,我用win xp。使用eclipse编写代码,在ms access 2007上构建数据库,并使用odbc - system dsn建立连接。在Win XP中,我的数据库连接工作正常,并于Java我的导航控件,似乎完美的,但在Windows 7上它会提示一个错误:如何避免java.sql.SQLException:[Microsoft] [ODBC Microsoft Access驱动程序]找不到文件'(unkown)'
java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] could not find file '(unknown)'.
我已经添加了32位ODBC上c:windows\syswow64
并建立了管理工具的连接/ odbc但仍然提示我有这个错误。我错过了什么?
答
您必须在管理工具中添加到Microsoft Access Driver中。
如果不工作做的事:
try
{
//your code
}
catch(Exception ex)
{
}
这是我的代码:
public void dbconnect1(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
condb1 = DriverManager.getConnection("jdbc:odbc:Datab1");
stdb1 = condb1.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql = "Select * from Table1";
rsdb1 = stdb1.executeQuery(sql);
if (rsdb1.next()){
textid.setText(rsdb1.getString("id"));
textfn.setText(rsdb1.getString("fn"));
textln.setText(rsdb1.getString("ln"));
textdep.setText(rsdb1.getString("dept"));
textpos.setText(rsdb1.getString("position"));
textyearh.setText(rsdb1.getString("yearhired"));
} else {JOptionPane.showMessageDialog(null,"connection in charge");}
} catch (Exception ex){JOptionPane.showMessageDialog(null,"error connect"+ex);}
}
你有没有印在异常错误?如果是这样,他们说什么? – javaGeek