使用 JDBC 连接 Oracle 时,如果 URL 写成:jdbc:oracle:thin:@192.168.1.100:1521:sid (192.168.1.100 是本机 IP)
此时在获取 Connection 时将出现以下异常。 java.sql.SQLException: The Network Adapter could not establish the connection但如果将 URL 写成 jdbc:oracle:thin:@localhost:1521:sid (localhost 也可以换成 127.0.0.1)
就没有问题。这样导致我无法从另外的 pc 连接当前这台 pc 上的 oracle 了~~望赐教~~

解决方案 »

  1.   

    估计是oracle权限问题,没有开放外界访问权限
      

  2.   

    可以的!
    oracle官方网站上面找。具体设置自己摸索吧!For JDBC Thin: 
    You must specify a full name-value pair connect string (the same as it might appear in the tnsnames.ora file) instead of the short JDBC Thin syntax. For example, instead of 
    "jdbc:oracle:thin:@host:port:sid"you would need to use a string of the form"jdbc:oracle:thin:@(DESCRIPTION="                    +
                           "(ADDRESS_LIST="              + 
                               "(ADDRESS=(PROTOCOL=TCP)" + 
                                        "(HOST=host)"    +                                      =
                                        "(PORT=port)"    +
                               ")"                       +
                           ")"                           +
                           "(CONNECT_DATA="              +
                               "(SERVICE_NAME=sid)"      +
                               "(SERVER=DEDICATED)"      +
                           ")"                           +
                         ")"
      

  3.   

    不太了解Oracle,不过SQL Server远程连接需要开启SQL Server Browser服务,Oracle是否也需要开启类似的服务?
      

  4.   

    进入ORACLE下面这个目录:
    oracle\product\10.2.0\db_1\network\ADMIN
    然后打开一个配置文件tnsnames.ora
    然后你去修改里面的 HOST 项就行了,把其值改成IP就行了,以后想用127.0.0.1的时候,再把HOST改回来就行了
    注意,做修改的时候一定要对配置文件做好备份哟