Link to home
Start Free TrialLog in
Avatar of kvkamesh
kvkamesh

asked on

How to connect to remote database using swing - oracle t ype 4 driver ?

Using java swing i want to connect the remote database(oracle) and retrive the database from that system. i want to use oracle type 4 driver. To use type 4 driver i need      username/password@hostname:portnumber:sid  
right give me an example of the above parameters. i have a remote system conecting to the internet what are the
parameters i want to expect from remote system?? please help me
Avatar of Ovi
Ovi

This is an example of creatig a connection using an Adabas driver.


public Connection connect() {
Connection con;
// Load driver for connection ...          
try {
      Class.forName("de.sag.jdbc.adabasd.ADriver");
} catch (ClassNotFoundException e) {
      System.out.println("JDBC driver not found");
    };
System.out.println("JDBC driver succesfully loaded.");//******************

try {
// make a connection to database      
       con = java.sql.DriverManager.getConnection(
           "jdbc:adabasd:"+"//"+host+"/"+"MYDB",
        "HARTI","ITRAH");
} catch (java.sql.SQLException e) {
      System.out.println("Error " + e.getErrorCode() +e.getMessage());
      System.exit(0);
};
System.out.println("SQL connection  succesfully started.");
return(con);
}

For your driver modify the lines :
Class.forName("de.sag.jdbc.adabasd.ADriver"); - point the String to your driver path.
con = java.sql.DriverManager.getConnection("jdbc:ORACLE I SUPOSE:"+"//"+HOST IP+"/"+"DATABASE SERVER NAME","DATABASE USER NAME","DATABASE USER PASSWORD");
... and make sure that your driver is in the classpath.
The simple answer is:

jdbc:oracle:thin:USERNAME/PASSWORD@HOST:PORT:SID

where SID is your database identifier, PORT is typically 1521, HOST is hostname or ip address.
And the name of the Driver class is:

oracle.jdbc.driver.OracleDriver

You can also use the getConnection( url, user,password ) method if
specify a url without user/password like this:

jdbc:oracle:thin:@HOST:PORT:SID
Avatar of kvkamesh

ASKER

HI
Thanks for your program. i need what are the parameters i want to pass:- username/password@hostname:portnumber:sid
I have a system no 1 it is connected to modem and it is connected to Internet. right. i have system number 2  is having another modem and it is connected to Internet ok.
Now i am using this string for connecting the oracle database at number 2 system.i am using type 4 driver in the fallowing string what are the parameters i want to pass? jdbc:oracle:thin:USERNAME/PASSWORD@HOST:PORT:SID
what is the username?(may be scott) what is the password? (may be tiger)what is the HOST? (may be hostname or ip address(give me example))what is the Port? (i know it is 1521) what is the SID?
thanks expecting early reply
HI
Thanks for your program. i need what are the parameters i want to pass:- username/password@hostname:portnumber:sid
I have a system no 1 it is connected to modem and it is connected to Internet. right. i have system number 2  is having another modem and it is connected to Internet ok.
Now i am using this string for connecting the oracle database at number 2 system.i am using type 4 driver in the fallowing string what are the parameters i want to pass? jdbc:oracle:thin:USERNAME/PASSWORD@HOST:PORT:SID
what is the username?(may be scott) what is the password? (may be tiger)what is the HOST? (may be hostname or ip address(give me example))what is the Port? (i know it is 1521) what is the SID?
thanks expecting early reply
For username, password port and sid you have to ask the administrator of
the database. port and sid can be found in tnsnames.ora or listener.ora in
$ORACLE_HOME/net/admin

For the hostname or ip you also have to ask the administrator of the system2.
If it has a static ip you can use that, if it has dynamic ip you have to find a way
to exchange this information between the two systems. A possible way is with
a dynamic DNS service, for example www.dhs.org.
ok i got your point for more clarification i am asking you again.i know that what you are explaining.Through LAN i have connected earlier to asking this question,  
jdbc:oracle:thin:scott/tiger@200.100.50.115:1521:orcl (200.100.50.115 this is my system IP)then i connected to my system. Now please tell me in place of IP(200.100.50.115) which Host Name(system IP or Internet Static IP or dynamic IP which ever it is) i want to connect the system no 2 through Internet. Assume that i have 2 systems in one place and i am a administrator. Both systems are connected to Internet through different connection. please help me
OK if I undertood it right you have 2 systems standing in the same room.
There is an ethernet connection between them. Both of these systems
have a modem which connects them to the internet.
The first system has the ip 200.100.50.115 on the ethernet interface.
The second has a similar one on its ethernet interface, for example
200.100.50.116

So there are two ways to connect to the second system:
You can connect over the internet but this makes no sense because
you have a faster connection, over ethernet.
So the better way is just connect to the ethernet ip of system 2
(200.100.50.116 or whatever its ip is).
If there is the same database with the same sid, user etc. then the url is:
jdbc:oracle:thin:scott/tiger@200.100.50.116:1521:orcl

And if you have a private LAN with the ip/netmask 200.100.50.0/255.255.255.0
or similar you should change these ip adresses to one of the private adress
spaces as described in RFC 1918 (http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc1918.html)
These address spaces are:

   10.0.0.0        -   10.255.255.255      (10/8 prefix)
   172.16.0.0    -   172.31.255.255     (172.16/12 prefix)
   192.168.0.0  -   192.168.255.255   (192.168/16 prefix)
HI we are closer.through ethernet we can connect as per your suggestion. i tried earlier only.
 i have given an example for your understanding.acutally i am looking to connect the remote system using this method.I have 2 systems. but both are not connected by ethernet. system no 1 having internet connection and system 2 having internet connection. both are entirely individuals. for testing purpose. for more clear one system is in INDIA and other is in UK or USA.
Now i want to use jdbc:oracle:thin:USERNAME/PASSWORD@HOST:PORT:SID
please tell what is the HOST name i want to mention.
username and password and port, sid we will give as per database i am confusing what we have to write in place of HOST. pleas help me. you understand my problem i want to connect the systems through Internet only. i know through  ethernet we can connect very fast. we are using the same since last 3 months. but i want to connect through Internet only. please help me.thank you for immediate replys
You want to make a connection from the system 1 to the system 2 over
internet and you need the IP of system2 (or hostname).
Now you need to know if the system 2 has a dynamic ip (most of the
users on internet get a dynamic id from their ISP) or a fixed ip.
can u give an example, assume i know their ISP. please the me the example.
Many ISP support both, fixed and dynamic id.
You should ask the administrator of system 2. He can tell you if system 2
has a fixed ip. If it has a fixed ip he can also tell you the hostname or if doesn't
have one the ip address.
If it has a dynamic ip address the administrator of system 2 and you have to find a
way for exchanging the ip address when it changes. There are several ways to do that.
He could send you (or your system) an EMail, he could write it to a file on hes homepage
where you can download the file or he coud setup a script for a dynamic DNS sytem like
www.dhs.org
Sorry that I can't help you anymore, only the administrstor of system 2 can.
in pace of HOST you can use either the fully qualified Internet host name (e.g.  data.yourdomain.com) or it's IP address (e.g. 198.0.0.1)  You can use the former if the host in properly in DNS, the latter will be required if you know it's IP address and it's not properly configured in DNS.

so, what you need to know is:  

What is the name of the host if it is in DNS?

or

What is it's IP address?
HI superschlonz
for example sytem IP is 200.100.50.125. And ISP static ID is 100.50.20.2 which one i have to mention in host place?
HI  jimsims
for example sytem IP is 200.100.50.125.And ISP static ID is 100.50.20.2 which one i have to mention in host place?
ASKER CERTIFIED SOLUTION
Avatar of superschlonz
superschlonz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The HOST parameter is the IP address or hostname of the system the database resides on
HI

Thanks for the same i will try and if connected i will inform you thanks. I have the same idea but i don't have infrastructure to test. Know my idea is exactly matching with your idea. thanks.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:


[points to supersclonz]


Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
sudhakar_koundinya
EE Cleanup Volunteer
---------------------
If you feel that your question was not properly addressed, or that none of the comments received were appropriate answers, please post your concern in THIS thread.