-1

I am using Netbeans IDE and Java and jdbc to connect to Oracle database locally (that is the database and the program are stored on same computer)

But I wanna access the database through program which is stored on different computer.

How to do that as well as what extra software is needed and what should be the URL for DriverManager.getConnection()

My current DriverManager.getConnection is something like this....

DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE",condb.usrnm,condb.psswrd);
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
Bhuvanesh Desai
  • 133
  • 1
  • 7
  • Assuming you have the same database technology, then just replace `localhost:1521` with the address of the server. – jr593 Feb 01 '17 at 10:27
  • possible duplicate http://stackoverflow.com/questions/1457716/what-is-the-mysql-jdbc-driver-connection-string your localhost should point to the hostname of the computer where database is ... – Redlab Feb 01 '17 at 10:29

2 Answers2

0

Try to change localhost into the hostname or the ip address of your db server. In the example below I have changed into server.remote.net.

DriverManager.getConnection("jdbc:oracle:thin:@server.remote.net:1521:XE",condb.usrnm,condb.psswrd);

Then pay attention to the port, I assume that your server is listening on port 1521. Because 1521 is Oracle server the standard port.

After that you have to be sure that there is network connection to your server. There are many ways to do it. As suggested by @YCF_L you could ping the server:

ping server.remote.net

or telnet

telnet server.remote.net 1521

Another important thing you have to pay attention is the XE keyword in the jdbc connection string. Which is the Oracle instance name. Your remote server can have an Oracle Instance named differently COMPANY_DATA

This means that your connection string could change into:

DriverManager.getConnection("jdbc:oracle:thin:@server.remote.net:1521:COMPANY_DATA",condb.usrnm,condb.psswrd);

On the other hand, on the remote computer there could be a different Database Engine. Like MySql, MS SQL Server, Postgres, etc. In this case the jdbc connection string changes much more.

freedev
  • 25,946
  • 8
  • 108
  • 125
0

You should to specify the right IP address of the target computer :

Connection con = 
DriverManager.getConnection("jdbc:oracle:thin:@ipOfTargetPc:1521:XE", condb.usrnm, condb.psswrd);

You can ping in the target computer and get the IP address.

Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140