Connect outside internet Oracle Database from inside intranet through JDBC

My desktop locates in company’s intranet, the oracle database server
is outside our intranet and has a public IP address.  There are several
steps to connect the outside internet Oracle database from inside
intranet through JDBC. To make sure the secure connection, you may need
the server side system administrator or DBA’s help.

1. Get the company’s public IP addresses.

Most company use proxy to connect Internet from intranet, and they
will keep a block of company’s public IP addresses for the IP mapping.
For example,  if I use proxy located in China, then my desktop’s public
IP address should be 
202.108.xxx.128/28. When I changed the proxy located in U.S, my public
IP addresses may lie in the block of

192.18.xxx.0/27.

Your public IP address can be found through
following web sites.

    http://www.whatismyip.org/

    http://www.displaymyip.com/


2. Ask the SA or DBA to do two things.

    One is to add the block of public IP
addresses in the server’s firewall filter, and enable those IP can
accessing the server.

    Two is opening the 1521 port to those
IP blocks. (1521 is Oracle’s default port)

3. JDBC source code

First, set the socks proxy.

       
System.setProperty("socksProxyHost", "192.18.xxx.xxx");
        System.setProperty("socksProxyPort", "1080");

Second, get the db connection

        
Class.forName("oracle.jdbc.driver.OracleDriver");
          ….
         Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@host_ip:1521:db_name",
dbuserid, dbpassword);

After completing upper steps, you should
get the connection successfully. At least, I had connecting a Internet
Oracle DB successfully.

I had met a error of "The Network
Adapter could not establish connection" when connecting a different
Oracle DB, I refer to following URL
http://www.websina.com/bugzero/kb/oracle-connection.html

As Oracle database may use MTS, it’s better to use following DB url

String dbUrl =

"jdbc:oracle:thin:@(DESCRIPTION="                    +
                       "(ADDRESS_LIST="              + 
                           "(ADDRESS=(PROTOCOL=TCP)" + 
                                    "(HOST=host_ip)"    +                                      =
                                    "(PORT=1521)"    +
                           ")"                       +
                       ")"                           +
                       "(CONNECT_DATA="              +
                           "(SERVICE_NAME=db_name)"      +
                           "(SERVER=DEDICATED)"      +
                       ")"                           +
                     ")"

Connection conn =
DriverManager.getConnection(dbUrl, dbuserid, dbpassword);

Please note that if the Oracle is lower
version than Oracle 8, the "SERVICE_NAME" should change to "SID".
Besides, the Oracle database I am testing is installed on Solaris
Platform. The Oracle on Windows platform need different configuration
for its random port issue, and that’s out of my interests.


Advertisements

关于 李力(Ada Li)
Entrepreneur, Community Leader, Software Engineer

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: