Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The Network Adapter could not establish the connection in jdbc connection

 
srinivas Doni
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all,

I am new to java. I am getting error[b]:"The Network Adapter could not establish" [/b]the connection while establishing connection to oracle database.


//code
try {

String jdbcurl = "jdbc:oracle:thin:@localhost:1521:" + "ORCL";

Class c= Class.forName("oracle.jdbc.driver.OracleDriver");

Driver d = (Driver) c.newInstance();

Properties p = new Properties();
p.put("user", "scott");
p.put("password", "tiger");

Connection con = d.connect(jdbcurl,p);
System.out.println(con);
} catch (Exception e) {
System.out.println("The exception raised is:" + e);
}


If anybody is familar with this one, can help me to resolve this error.

Advanced thanks to all,


withregards,
srini
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you have an Oracle server running on the same machine, and that Oracle server is listening on port 1521?
 
srinivas Doni
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Actually I installed VM ware and installed Winows Xp sp2 in that VM ware. later i installed Oracle. it is listening to port 1521 only. but i could not find
where i am getting error.

If anybody know about this problem, can help to me to resolve this error.






Advanced thanks to all
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So Oracle is listening inside the virtual machine? And you're running this code from the virtual machine? Because even though the virtual machine is running on the same physical hardware as your host operating system, it's not the same logical machine - it has its own IP address, name, etc.
 
srinivas Doni
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob Spoor,

how can i run with localhost. is it not possible?. if not, how can i know whether oracle is listening inside virtual machine or outside.

please let me know how can i resolve this error

Advance thanks to you,



With Regards,
srini
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Localhost means the logical machine (i.e. Windows installation, Linux installation, etc) where you are currently running on. Oracle will be listening wherever you installed it. You're the only one who knows if that's the virtual machine or its host machine.

If it's in the virtual machine and you're running your Java program in the host machine you can connect by replacing localhost with the IP address or server name of the virtual machine. You'll need to make sure there's no firewall blocking access.
 
srinivas Doni
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob Spoor,

connection established.Actually, it has taken another logical name in VM ware i.e.,(windows 7 & windows XP2 have taken different machine names).

Thanks Rob spoor for resolving this error.


Regards,
srini





 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic