This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes java.sql.SQLException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.sql.SQLException" Watch "java.sql.SQLException" New topic
Author

java.sql.SQLException

pratike shahh
Greenhorn

Joined: Nov 06, 2009
Posts: 5
Hi,
I am trying to connect to a Oracle Database. From my local machine I am able to use SQL Plus and connect to the Database.

This is code I am using:
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbcracle:thin:@Database_IP:1521:SID","usr","pwd");
DatabaseMetaData meta = conn.getMetaData();
System.out.println("JDBC driver version is " + meta.getDriverVersion());

Where SID value is what I obtained from select instance_name from v$instance;
and Database_IP is the IP address of the server hosting Oracle.

However I get the exception:
java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ReadOracle.main(ReadOracle.java:8)

Please help me solve this issue,
Thanks,
Pratik
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
make sure listener is up and running.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
pratike shahh
Greenhorn

Joined: Nov 06, 2009
Posts: 5
Thanks for the reply.
I dont have access to the server, is this something I can do via SQL Plus..
Or how can I check that.

Sorry but I am fairly new to all this..

Regards,
Pratik
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
This link may help you

webpage

Especially look at this response parthas_k@yahoo.com in that link
pratike shahh
Greenhorn

Joined: Nov 06, 2009
Posts: 5
Thanks for the reply,
I've already tried suggestions in that link, but still the same error.

Any more suggestions...
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
pratike shahh wrote:Thanks for the reply,
I've already tried suggestions in that link, but still the same error.

Any more suggestions...


Did you try everything stated in the link?

Did you check the listener is running?

Did you see the tnsnames.ora file for the valid information?
srinivas srinivasmeenavalli
Ranch Hand

Joined: Jul 13, 2008
Posts: 65
are you able to ping server IP
open command prompt and try to run c:/ping Database_IP
srinivas srinivasmeenavalli
Ranch Hand

Joined: Jul 13, 2008
Posts: 65
I have one more question . What kind of program it is ?
is it being called from a applet or stand alone ?
pratike shahh
Greenhorn

Joined: Nov 06, 2009
Posts: 5
This is a test program which I am trying to run from my local machine.
Eventually this will be a middleware program for one of our interfaces.
pratike shahh
Greenhorn

Joined: Nov 06, 2009
Posts: 5
okay this is what I tried and it seems to work:
1. Created s DSN entry on my machine
2. And then used:
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection con=DriverManager.getConnection(“jdbcdbcSN name”,”usr”,”pwd”);

And this seems to work, I tried a test query and it seems to work..

Is this is also a right way to do so..
Eventually this program will run on one of our servers as an Interfac/middleware program..

Thanks,
Pratik
 
 
subject: java.sql.SQLException