`
dong_java
  • 浏览: 42145 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

推荐使用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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics