我使用的是java se和windows7上的microsoft access /jet数据库。在使用win7之前,我使用的是win。使用eclipse编写代码,在ms access 2007上建立数据库,并使用odbc - system dsn建立连接。在win xp上,我的数据库连接工作正常,java上的导航控件看起来也很完美,但在Windows7上,它会提示一个错误:
java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] could not find file '(unknown)'.我已经在c:windows\syswow64上添加了32位odbc,并在管理工具/odbc中建立了连接,但仍然提示我该错误。我遗漏了什么?
发布于 2014-03-19 10:08:23
您必须在管理工具中添加到Microsoft Access驱动程序。
如果这不起作用,那就这么做:
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);}
}https://stackoverflow.com/questions/22494629
复制相似问题