wood burning stoves 2.0*
The moose likes JDBC and the fly likes Establishing Connections to a Data base on a different machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Establishing Connections to a Data base on a different machine" Watch "Establishing Connections to a Data base on a different machine" New topic
Author

Establishing Connections to a Data base on a different machine

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi all,
I want to use the database which is existing remotely( in a different firm).
I am using the same format to connect to the other company's database.
con = DriverManager.getConnection("jdbc racle:thin:@hostaddress ort:sid","username","passwd");
This same convention, if I try using my machine name or my machine's IP is working fine.
But when I try to connect to the remote machine, nothing happens.
I put SOP statements before this line and after this line.
SOP statement before the line is getting printed out, but not the one before...
Any idea of what is causing the problem.
We are behind a firewall. I think that is the issue. If so, what should I need to solve the problem. In any case, I want to use the database also...
Any suggestions and help welcome
Thanks,
Maya

Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
Can you hit the remote machine from yours ?
PING..
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Fred,
I don't think.
this is the response when i try to Ping
Pinging xx.xx.xx.xx with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for xx.xx.xx.xx:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Maya
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
so thats where your problem lies
the remote system is not on your network so you can not use it
where is this machine?
is it yours?
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
hi, as long as you can�t hit the other machine you�re not gonna be able to connecto to it. So first make sure you can get to it before trying to do the connection.
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
If you�re trying to access a db using the internet you should do something like this:
static String Driver = new String("org.postgresql.Driver");
static String Url = new String("jdbc ostgresql://www.mrbrasilia.com.br/dbfree");
notice tha this directory should be mapped to the port of the DB and of course that in this case the db is PostGree.
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Fred,
The machine is neither mine nor my company's. It is my client's machine located in a different building...
So, what shoould I do ?
Maya
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Marcos,
Thanks for the response.
The machine is neither mine nor my company's. It is my client's machine located in a different building...
So, what should I do ? I want to access it from my pc... to do the testing.
Maya
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
your client will have to give you access either through a FTP site or by dialing into their network
once you become part of their network
you can use the connection spec with a username and password that they give you
good luck
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Fred,
My client has provided me,
their host address
port
sid
username
password
So, so I need anything more...
Maya
cardwell cupp
Ranch Hand

Joined: Aug 16, 2001
Posts: 66
Just wondering...
When you do try to connect with your code, is there an exception thrown (i.e. data source name not found or something like that.
Trying putting it into a try catch statment and output the exception.
Thanks
Cardwell
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi Cardwell,
This is the code,
I have caught all the exceptions.
import java.sql.*;
public class test15
{

public static void main(String[] args)
{
Connection con = null;
int iRowCount = 0;
Statement stmt = null;
String sDriver =
"oracle.jdbc.driver.OracleDriver";

try // Attempt to load the JDBC driver
{ // with newInstance
Class.forName( sDriver ).newInstance();
System.out.println("Driver loaded");
con = DriverManager.getConnection("jdbc racle:thin:@ddd.ddd.ddd.ddd:1526:dddd","dddd","dddd");
System.out.println("Connection got");

stmt = con.createStatement();
}catch(SQLException se){
se.getMessage();
}
catch( Exception e ) // error
{
e.getMessage();
System.err.println("Failed to load current driver.");
} // end catch

} // end main
} // end class test15

The output is only Drver loaded.
Am I missing something ?
Maya
cardwell cupp
Ranch Hand

Joined: Aug 16, 2001
Posts: 66
Sorry...
I think I may have given you some wrong info.
If you are using the Oracle JDBC Thin Driver (Type-4), the JDBC URL will be: "jdbc racle:thin:@whatever.what.wh.edu:1521:ORCL".
If you want to use the Native Oracle JDBC driver, the following code will take care about the connection.
DriverManger.registerDriver(new oracle.jdbc.driver.OracleDriver());
Sorry about that...Try using the above info...
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Cardwell,
Still no sops.. printed out..
weird..
\
Maya
venugopal askani
Greenhorn

Joined: Aug 20, 2001
Posts: 16
hey maya
try out the no 1521 instead of 1526 and let me know..
i suppose it has to connect pretty fine..
Regards
Venu
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi Cardwell,
I put a lot of SOPs and got this output...
well, quite expected.
Io exception: The Network Adapter could not establish the connection
Venu,
The port number that my client gave to me is 1526, no idea ... I had already tried with 1521, still no rays of hope.
Maya
Marcos Maia
Ranch Hand

Joined: Jan 06, 2001
Posts: 977
Here goes some sugestions to try examples ok,and change the ORCL from the end to ORACLE I�ve seen this problem before:

java.util.Properties props = new java.util.Properties();
props.put("user", "your_user");
props.put("password", "the_password");
java.sql.Driver d = (java.sql.Driver)Class.forName("oracle.jdbc.driver.OracleD
river").newInstance();
java.sql.Connection conn = d.connect("jdbc racle:thin:@HOST_ADRESS:PORT:ORACLE", p
rops);
OR:

Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
java.sql.Connection conn =
Driver.connect("jdbc racle:thin:@HOST_ADRESS:PORT:ORACLE", "user", "password");
OR:

java.util.Properties props = new java.util.Properties();
props.put("user", "your_username");
props.put("password", "the_password");
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
java.sql.Connection conn =
Driver.connect("jdbc racle:thin:@HOST_ADRESS:PORT:ORACLE", props);
regards.
sivakanth narra
Greenhorn

Joined: Aug 26, 2001
Posts: 2
hai all
i am new to this section ,i have a problem with connecting to oracle by using odbc driver.
First on windows 95 i installed oracle 7.3 and tryed to connect to it using odbc(Microsoft odbc driver for oracle) driver ,when i run my java application an window appears on the screen saying oracle client and network components where not installed and install them.
i uninstall the oracle 7.3 and installed oracle 8 but the same error is comeing .
At last i changed my os from windows 95 to windowsNT and istalled oracle8i ,but the sad thing is i found tha same error
please help me

Dhaneep Raghavan
Greenhorn

Joined: Aug 13, 2001
Posts: 4
Hi maya,
Same code is working if database in the same
machene.But it is not working in the different machene.
I think I can help you.
What you wants to do know,
Just go to the "windows" folder.There you can see one file
called "hosts".Add one line like this
'IP address of the remote machene which reside oracle' 'name of the remote machene.'
Eg
164.164.10.1 linuxdev.dhaneep.com

Dhaneep
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi Dhaneep and Marcos,
Thanks for the valuable suggestions.
I don't jave time to try this out today.
I will be doing it tomorrow or day after it.
Will let you know afterwards.
Thanks,
Maya
venugopal askani
Greenhorn

Joined: Aug 20, 2001
Posts: 16
Hi Maya,
Well first check whether you can connect to the remote machine using the Oracle Client that is installed on your machine. Else please try connecting to that server by using some client software like TOAD. When that is tested first then you can try connecting using the java code which Marcos Maia is specified. Most probably i think you are unable to connect to that machine. If any of these test are not successful then try creating a DSN in Windows environment if you have got one installed. This will solve the problem instead of us shooting in the dark.
Hope this gives some help for ur problem
Regards
Venu
william cummings
Greenhorn

Joined: Aug 29, 2001
Posts: 2
Hi,
I have experience this problem before. There are a couple of possible steps to take.
1st.) Check with your security admin. and determine if your corporate firewall allows outgoing traffic on the port/1526 or 1521.
2nd.) Check with your clients security admin. and determine if your client's corporate firewall allows incoming traffic on the port/1526 or 1521.
3rd.) Ensure that the ip address your client has given you is a externally addressable ip, not an address that is internal to your clients network.
For example,
Your client internal ip address may be 192.168.1.100, but the externally viewable address 202.xxx.xxx.xxx. When traffic hits the firewall on a specific ip/port (i.e. 202.xxx.xxx.xxx:1521) the external address ort is translated to an internal address ort (i.e. 192.168.1.100:1521) this is called Network Address Translation. (NAT)
Hope this helps
William Cummings
V Srinivasan
Ranch Hand

Joined: Aug 16, 2000
Posts: 99
Can anybody tell me, do we not really need to establish network connection via URL object to access the machine at different location. I think that sort thing is missing here. java.sql.connection is sufficient to access remote machine, without doing socket programming. I am confused.
Regards
venugopal askani
Greenhorn

Joined: Aug 20, 2001
Posts: 16
hey maya
i totally agree with william. The issues which he address were also faced by me. But in our case like our client had a firewall in between and when we had given a list of ports being used he had open the ports for my servers IP address..
Kindly check the ports and the firewall and the proxy stuff with ur security admin..
Regards
Venu
Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
Hi William/Venu,
Yes, the problem is woth the firewall. there is some problem with the ports of the firewall.
In our firewall, we opened the port, but what we think is the client's port is still not permitting a log on .
We are on that part.
Thanks for then suggestions.
Maya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Establishing Connections to a Data base on a different machine
 
Similar Threads
MS Access - how to read query
Compilation errors scrolling off the screen
JDBC, orion server and SQL Server
Need help - MySQL + Solaris
Connecting between Applet and database