不配置ODBC数据源,用JDBC-ODBC桥连接Access数据库
-----------------------------------------------------------------------------------------查了许多注册表的知识,终于搞定,这样就可以不用配置ODBC数据源了,很方便,拿来与大家分享!
Connection con;
Statement stmt;
try{
//Load JDBC driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//注意DBQ的写法
String url = "jdbc:odbc:driver={Microsoft Access Driver
(*.mdb)};DBQ=E:\\db1.mdb";
con = DriverManager.getConnection(url, "sa", "");
stmt = con.createStatement();
String query = "select * from faq";
ResultSet rs = stmt.executeQuery(query);
while ( rs.next() )
{
String str = rs.getString( "name" );
out.print( str );
}
}
catch( Exception e ){
e.printStackTrace();
}
已经在Win2000 Professional + JDK1.4.0 + Tomcat 4.0.3 + Aceess 2000下测试通过!