java jdbc access数据库_如何使用JDBC从Java连接到Access数据库? (How can I connect to an Access database from Java us...

最佳答案

英文原文

you can use

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// set this to a MS Access DB you have on your machine

String filename = "d:/java/mdbTEST.mdb";

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";

database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end

// now we can get the connection from the DriverManager

Connection con = DriverManager.getConnection( database ,"","");

中文翻译

你可以使用

的Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver中" );

//将此设置为您计算机上的MS Access DB

String filename =" d:/java/mdbTEST.mdb" ;

String database =" jdbc:odbc:Driver = {Microsoft Access Driver(* .mdb)}; DBQ =" ;

database + = filename.trim()+" ; DriverID = 22; READONLY = true}" ; //添加到最后

//现在我们可以从DriverManager获得连接

Connection con = DriverManager.getConnection(database," " ," " );

you can use

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// set this to a MS Access DB you have on your machine

String filename = "d:/java/mdbTEST.mdb";

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";

database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end

// now we can get the connection from the DriverManager

Connection con = DriverManager.getConnection( database ,"","");

你可以使用

的Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver中" );

//将此设置为您计算机上的MS Access DB

String filename =" d:/java/mdbTEST.mdb" ;

String database =" jdbc:odbc:Driver = {Microsoft Access Driver(* .mdb)}; DBQ =" ;

database + = filename.trim()+" ; DriverID = 22; READONLY = true}" ; //添加到最后

//现在我们可以从DriverManager获得连接

Connection con = DriverManager.getConnection(database," " ," " );

参考答案2

参考答案3

An alternative - JDBC to ODBC Bridge - which has a client/server architecture is also available...

This means the Java application and Access database can reside on different machines.

The following link will give you an idea of what goes where --

参考答案4

public class NewClass {

static final String DRIVER = "com.mysql.jdbc.Driver";

static final String DATABASE_URL = "jdbc:mysql://localhost/databasename";

Connection connection = null;

Statement statement = null;

ResultSet resultSet = null;

public void dataQuery(String queryData) {

Class.forName(DRIVER);

connection = DriverManager.getConnection(DATABASE_URL, "root", "");

statement = connection.createStatement();

resultSet = statement.executeQuery(queryData);

while (resultSet.next()) {

System.out.println(resultSet.getObject(1));

}

}

catch (Exception e) {

System.out.println("error Accessing");

}finally {

try {

resultSet.close();

statement.close();

connection.close();

} catch (Exception exception) {

System.out.println("error closing ");}

}

}

}

参考答案5

You can use ODBC connection to connect to Access Database from Java.

See the following example

参考答案6

Now that the JDBC-ODBC Bridge has been removed from Java (since Java SE 8), future readers should consider using the UCanAccess JDBC driver instead. For more information see

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值