Introduction - If you have any usage issues, please Google them yourself
~给你个不许要数据源直接连接的例子~连接access要制定到它数据库的mdf文件
Connection conn=null
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)} DBQ="+DBpath
conn=DriverManager.getConnection(url,"","")
}
catch (ClassNotFoundException e)
{
JOptionPane.showMessageDialog(null,e)
}
catch (SQLException e)
{
JOptionPane.showMessageDialog(null,e)
}
注意事项:
1.其中的DBpath即是数据库的路径,可以是相对的,也可以是绝对的。
2.尤其要注意url字符串中大括号中的空格一定要有,即Microsoft Access Driver (*.mdb)这里的空格一 定要保留,否则会报错。
3.getConnection()方法中后两个参数是DB的用户名和密码,根据自己的情况设置。