推荐使用Oracle 10.2.0.3的JDBC驱动

1。推荐使用Oralce比较新的10.2.0.3 JDBC Drivers。这个版本对比9.2的最大的好处是DriverManager.setLoginTimeout函数是起作用的。设置了这个参数,在恶劣的网络环境中就不会有连接数据库的函数长时间不返回的情况。

2。JDBC Developer!ˉs Guide and Reference 10g Release 2 (10.2)
给出的连接数据库的示例:
import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;
class JdbcTest {
public static void main (String args []) throws SQLException {
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@//myhost:1521/orcl");
ods.setUser("scott");
ods.setPassword("tiger");
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp");
// Print the name out
while (rset.next ())
System.out.println (rset.getString (1));

//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
这里使用了OracleDataSource,而不是以前的DriverManager。这样可以避免因为DriverManager.getConncetion方法是一个同步方法,而导致的线程死锁和应用服务器挂起问题。并且效率更高。OracleDataSource.setLoginTimeout可以设置连接超时时间。与DriverManager.setLoginTimeout的作用是一样的。推荐设置为3秒。在恶劣的网络环境中,应用程序就要对数据库狠一点。

Oracle Database 10g Release 2 (10.2.0.3) JDBC Drivers下载地址:
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.html
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值