• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to connect oracle 11g r1 database with java program.

 
Abhishek Nayak
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i am trying to connect oracle 11g with my java program in eclipse IDE, and i have added ojdbc6.jar in class path.
Databse Name: Oracle 11g r1 Enterprise edition.
operating system: windows 7 64bit.

my code is:



above program throws below exception:

java.sql.SQLException: The Network Adapter could not establish the connection
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:199)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:480)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:413)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at abhishek.Connect.main(Connect.java:12)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:328)
at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:421)
at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:630)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:206)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:966)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:292)
... 7 more
Caused by: java.net.UnknownHostException: //localhost
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:127)
at oracle.net.nt.ConnOption.connect(ConnOption.java:126)
at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:306)
... 12 more

can anyone tell me what's wrong am doing?
 
Mansukhdeep Thind
Ranch Hand
Posts: 1158
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you able to connect to the DB via Oracle directly using same credentials and is the test connection successful? Secondly, what is the name of DB that you created after installation of Oracle?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this discussion would fit better on one of our database fora. Moving.
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You gave your DB URL as: "jdbc:oracle:thin:@//localhost:1158:v$instance"

The port 1158 is usually the port that the Oracle Enterprise Manager application listens on, so you won't be able to use it for a JDBC connection. The default port for the database listener is 1521. Try that and see if it works.

Also, the usual structure of an Oracle JDBC URL is something like "jdbc:oracle:thin:@myhost:1521:orcl" where your DB's name is "orcl" (this is the usual default), so you should also check that you are providing the right DB name in the right format.

You could check in your TNSNAMES.ORA file (this tells Oracle clients like SQL*Plus how to connect to the DB) to find the port and name of your target database, and make sure you use those details in a valid JDBC URL.
 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you must have resolved the issue by now, if not, you might want to check if database is installed on your local machine or not. Some issue with connection parameters only. Check port and other details pointed in previous comments.

Vinod
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic