Jackcess is a pure Java library for reading from and writing to MS Access databases (currently supporting versions 2000-2007). // Displaying the contents of a table: System.out.println(Database.open(new File("my.mdb")).getTable("MyTable").display()); // Iterating through the rows of a table: Table table = Database.open(new File("my.mdb")).getTable("MyTable"); for(Map<String, Object> row : table) { System.out.println("Column 'a' has value: " + row.get("a")); } // Searching for a row with a specific column value: Map<String, Object> row = Cursor.findRow(table, Collections.singletonMap("a", "foo")); if(row != null) { System.out.println("Found row where 'a' == 'foo': " + row); } else { System.out.println("Could not find row where 'a' == 'foo'"); } // Creating a new table and writing data into it: Database db = Database.create(new File("new.mdb")); Table newTable = new TableBuilder("NewTable") .addColumn(new ColumnBuilder("a") .setSQLType(Types.INTEGER) .toColumn()) .addColumn(new ColumnBuilder("b") .setSQLType(Types.VARCHAR) .toColumn()) .toTable(db); newTable.addRow(1, "foo"); // Copying the contents of a JDBC ResultSet (e.g. from an external database) into a new table: Database.open(new File("my.mdb")).copyTable("Imported", resultSet); // Copying the contents of a CSV file into a new table: Database.open(new File("my.mdb")).importFile("Imported2", new File("my.csv"), ",");
// Displaying the contents of a table:
System.out.println(Database.open(new File("my.mdb")).getTable("MyTable").display());
// Iterating through the rows of a table:
Table table = Database.open(new File("my.mdb")).getTable("MyTable");
for(Map<String, Object> row : table) {
System.out.println("Column 'a' has value: " + row.get("a"));
}
// Searching for a row with a specific column value:
Map<String, Object> row = Cursor.findRow(table, Collections.singletonMap("a", "foo"));
if(row != null) {
System.out.println("Found row where 'a' == 'foo': " + row);
} else {
System.out.println("Could not find row where 'a' == 'foo'");
}
// Creating a new table and writing data into it:
Database db = Database.create(new File("new.mdb"));
Table newTable = new TableBuilder("NewTable")
.addColumn(new ColumnBuilder("a")
.setSQLType(Types.INTEGER)
.toColumn())
.addColumn(new ColumnBuilder("b")
.setSQLType(Types.VARCHAR)
.toColumn())
.toTable(db);
newTable.addRow(1, "foo");
// Copying the contents of a JDBC ResultSet (e.g. from an external database) into a new table:
Database.open(new File("my.mdb")).copyTable("Imported", resultSet);
// Copying the contents of a CSV file into a new table:
Database.open(new File("my.mdb")).importFile("Imported2", new File("my.csv"), ",");
url:jdbc:access:///f:/MyEclipse/MyEclipse5.5/work/Car4_2/Car/database/Car.mdbf:后面是access存在的地址
我记得我以前用hibernate做过,应该可以的
import java.sql.*;
import java.io.*; class Access{
public static void main(String[] args){
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\helpdb.mdb";
Connection conn = null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection(url , "" , "");
Statement statement=conn.createStatement();
ResultSet rs=statement.executeQuery("select * from TAttachment"); while(rs.next()){
System.out.println(rs.getString(1));
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(conn!=null)
conn.close();
}catch(Exception e){
e.printStackTrace();
}
}
}//end of main
}
楼主是要这种么 也不用设置什么数据源还是说要存java驱动啊在windows的话不建议用纯java驱动 我下了几个效果不好 微软的兼用型不错 access就不考虑太多速度了
我可以很肯定的告诉你。
N多人用它作为数据使用,曾经我也很努力说用还不如用MYSQL,最后我沉默了。
url:jdbc:access:///f:/MyEclipse/MyEclipse5.5/work/Car4_2/Car/database/Car.mdb 这样是对的
DB_URL = jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=PhoneBook.mdb
USER = ""
PSD =""driver和url上面都有了,蓝色的部分就是mdb文件的路径,可以是绝对路径也可以是相对路径哦!