我写了一段简单得java程序通过 thin 驱动来连接RAC数据库,
经常是一会能练上,一会连不上,高不懂?谁遇到过这种情况啊
/*
 * Main.java
 *
 * Created on 2005年9月15日, 下午4:01
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */package javaapplication1;import java.net.ProxySelector;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;/**
 *
 * @author Administrator
 */
public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
        
        try {
            Driver driver = (Driver) Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            DriverManager.registerDriver(driver);
        } catch (Exception e) {
        }
        Connection con = null;
        try {
            System.out.println("aaaa");
            ProxySelector.setDefault(null);
            System.out.println("bbbb");
            con = DriverManager.getConnection("jdbc:oracle:thin:@(description=(address_list= (address=(host=192.168.0.1) (protocol=tcp)(port=1521))(address=(host=192.168.0.2)(protocol=tcp) (port=1521)) (load_balance=yes)(failover=yes))(connect_data=(service_name= zytl)))", "scott", "tiger");
            //logger.info("创建数据库连接成功:"+URL);
            System.out.println("ssss");
            Statement st = con.createStatement();
            System.out.println("dddd");
            ResultSet rs = st.executeQuery("select * from test");
            System.out.println("eeee");
            while(rs.next())
                System.out.println(rs.getString("id"));
            System.out.println("ffff");
        } catch (Exception e) {
            System.out.println(e);
        }finally{
            try{
                con.close();
            }catch (Exception e) {
                System.out.println(e);
            }
        }
}/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code application logic here
    new Main();
}}

解决方案 »

  1.   

    就是本地局域网上面得啊,有时候可以脸上,有时候就不行,怪异,就在getConnection得时候出错,
    SQLException,网络适配器什么什么错误,关键时有时候可以连上,但是连接单独得一台就没有问题,nnd
      

  2.   

    你本机上是不是装了防火墙?如果是, 你在连接时先关闭或disable它,试拭看
      

  3.   

    还有程序结束时你要保证connection一定得close!!否则在你的程序结束时该连接还会保持在数据库上
    异常改一下:
    finally{
                //if conn.state open
                //conn  close
            }