如何在JAVA中通^OLEDBB接ACCESS?

manchonu發表於2006-05-15
如何在JAVA中通^OLEDBB接ACCESS?
因槲頁霈F了"Too Many Client Tasks"的e`...foledb可解Q...
我的ADO封b如下,指教:

package mainPack;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

public class SOINC_ADO {
private Connection con;
private Statement sql;
private ResultSet rs;
private String action;
private ReentrantLock lock=new ReentrantLock();

public ResultSet exec(String action, String sqlStatement){
this.action=action;

//try to set up the JDBC-ODBC Bridge
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(Exception e){
System.out.println("Connection Error: "+e);
}

//try to make connection & execute the sql statement
lock.lock();
try{
con=DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};" +
"DBQ=D:/Kevin/selfProgramming/SOINC_First_Model/Database/SOINC_Schedule_DB.mdb");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
if (this.action.equalsIgnoreCase("Update")){
sql.executeUpdate(sqlStatement);
this.rs=null;
//System.out.println("Update Successed.");
}
else if (this.action.equalsIgnoreCase("Query")){
this.rs=sql.executeQuery(sqlStatement);
//System.out.println("Query ResultSet is created.");
}
}catch(Exception e){
System.out.println("SQL Error: "+e);
}
return rs;

}//end exec()

public void closeCon(){
try{
//this.rs.close();
this.con.close();
lock.unlock();
}catch(Exception e){;}
}

public static void main(String[] args) {

}//end main()
}

相關文章