如何在JAVA中通^OLEDBB接ACCESS?

06-05-15 manchonu
如何在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()

}

banq
2006-05-15 18:15
这年头还通过Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

连接数据库,你不怕软件系统慢吗?准备泡杯茶回来再看运行结果?

使用连接池,或者通过JNDI使用服务器的连接池即可。

manchonu
2006-05-15 19:15
那......有什么提h呢?

e光是批u......

manchonu
2006-05-15 19:17
那......有什么具w提h呢?

我懂的就不@幼隼?

e著批u......┱指教.

猜你喜欢