如何将.mdb数据库连接到JDBC?
来源: 互联网 发布时间:2015-06-12
本文导语: 如何将.mdb数据库连接到JDBC; 我将java.jdbc.jdbcodbcDriver 配置到了JBuilder; 同时我在 Database Pilot 能看到myData.mdb; { Properties pro=new Properties(); pro.put("user","admin"); pro.put("password","admin"); Conncetion con=Drive...
如何将.mdb数据库连接到JDBC;
我将java.jdbc.jdbcodbcDriver 配置到了JBuilder;
同时我在 Database Pilot 能看到myData.mdb;
{
Properties pro=new Properties();
pro.put("user","admin");
pro.put("password","admin");
Conncetion con=DriverManager("jdbc:odbc:myData",pro);
}
运行完后总是con==null;
请问.mdb怎么样连接上?
我将java.jdbc.jdbcodbcDriver 配置到了JBuilder;
同时我在 Database Pilot 能看到myData.mdb;
{
Properties pro=new Properties();
pro.put("user","admin");
pro.put("password","admin");
Conncetion con=DriverManager("jdbc:odbc:myData",pro);
}
运行完后总是con==null;
请问.mdb怎么样连接上?
|
不建立DNS直接使用JDBC-ODBC访问ACCESS数据库的方法
public class access
{
public static void main(String[] args)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
java.sql.Connection conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=test.mdb;PWD=","","");
java.sql.Statement st = conn.createStatement();
java.sql.ResultSet rs = st.executeQuery("select * from table1");
} catch (SQLException e) {
System.out.println(e.toString());
}
System.out.println("over");
}
}
public class access
{
public static void main(String[] args)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
java.sql.Connection conn = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=test.mdb;PWD=","","");
java.sql.Statement st = conn.createStatement();
java.sql.ResultSet rs = st.executeQuery("select * from table1");
} catch (SQLException e) {
System.out.println(e.toString());
}
System.out.println("over");
}
}