1. 程式人生 > >LINUX平臺 java怎麼直接連線access資料庫dbf檔案

LINUX平臺 java怎麼直接連線access資料庫dbf檔案

一、WINDOWS常見的方法:

                  String mdbFile = StringUtils.getServerRoot() + "\aftn.mdb";
		mdbFile = mdbFile.substring(1);
		String dbUr1 = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" + mdbFile;
		log.debug(dbUr1);
		String user = "";
		String password = "";
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			conn = DriverManager.getConnection(dbUr1, user, password);
		} catch (ClassNotFoundException e) {
			log.error("獲取連結失敗", e);
		} catch (SQLException e) {
			log.error("獲取連結失敗", e);
		}

這個方法只能在window平臺使用,在linux 或unix下使用會使應用app崩掉。我們如何能像我們的java語言一樣支援任何作業系統呢?我們需要借用東風才行,那裡的東風呢?

HXTT,她提供跨平臺的ACCESS資料庫訪問支援。示例程式碼如下:

		String mdbFile = StringUtils.getServerRoot() + "\aftn.mdb";		
		mdbFile = mdbFile.substring(1);
		String dbUr1 = "jdbc:access:////" + mdbFile;
		log.debug("dbUr1="+dbUr1);
		String user = "";
		String password = "";
		try {
			Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();
			conn = DriverManager.getConnection(dbUr1, user, password);
		} catch (Exception e) {
			log.error("獲取連結失敗", e);
		}



需要jar包支援。通過jdbc直接連。驅動是com.hxtt.sql.access.AccessDriver

http://www.hxtt.com/access.zip可以下到,

還需要資料庫方言com.hxtt.support.hibernate.HxttAccessDialect

資料庫方言包在http://www.hxtt.com/test/hibernate.jar可以下到。