Trying to connect to Oracle!!!

Posted on 2000-05-02
Last Modified: 2011-10-03
1) I have installed Oracle client(releas 8.1.5) on my WIN98.

2) I am able to connect to a dsn called "" through
Oracle-OraHome --> Network Administration --> Oracle ODBC Test
and I have succeeded connecting to a dsn (under the tab of "Machine Data Source") named tryDb, which is an Oracle ODBC Driver (not Microsoft), configured with the service name of In other words - I have the connection working!!!

3) I have the JDK 1.2.2 installed.

4) I am unsuccessfully trying to access Oracle data base (under the service name of through my java application. The rellevant code for loading the driver and for getting the connection is the following:

import java.sql.*;
import java.awt.*;

public class oracleConnectTrial
  public void selectData()
    Connection con = null;            
     // Load the Driver class file
//Make a connection to the ODBC datasrc
con = DriverManager.getConnection("jdbc:odbc://", "usr", "pass");

*** getConnection fails and throws me
*** an UnsatisfiedLinkError! The exception's getMessage() gives me the following:

"sun/jdbc/odbc/JdbcOdbc.allocEnv  Possible causes: If you are trying to use J/Direct (@dll.import), check your compiler version (for JVC, requires 4336 or greater.) If you are trying to use RNI, there are new requirements: see documentation."

5) I am using Microsoft Visual J++ version 8171. I am not, to my knowledge, using J/Direct (@dll.import)
or RNI, and I am asking for your detailed help since this is my first application ever that needs to access a database.

6) Please explain if u know; Thank-you.
Question by:itailevitan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3

Expert Comment

ID: 2770003
If you've set up the ODBC on your machine with the service name of, then your getConnection statement should work with:

con = DriverManager.getConnection("", "usr", "pass");

You don't need the '//'.

Expert Comment

ID: 2770004
If you have any more trouble, drop another comment and I'll be glad to help.

Laminamia :)

Author Comment

ID: 2770151
Hello Laminamia - thanks for answering. i have already tried that before posting the question, and I do apologise for not stating this. The problem still holds. I am thinking of downloading the type 4 thin driver and retrying. Anty other suggestions?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 2770229
Laminamia changed the proposed answer to a comment

Author Comment

ID: 2770474
I tried changing the driver. Here is the code and the SQLException message-

// Load the Driver class file
// Make a connection to the data base
con = DriverManager.getConnection("", "usr", "pass");

the exception message is:
"The Network Adapter could not establish the connection"

which is partly good - because atleast my application loads the driver. Any ideas regarding this Adapter bussiness?!

Expert Comment

ID: 2771688
I would guess that your problem revolves around your connect string.  Specifically, you stated above that you created a Microsoft DSN called, as well as an entry in your TNSNames file called

The JDBC URL (the first argument of the getConnection method) is expecting you to provide the URL for the box where your Oracle instance is located.  If you can't ping, then that's your problem.  Either replace it with the URL or ip address of your Oracle box...for example:

con = DriverManager.getConnection("jdbc:oracle:thin@","usr","pass");

The SID which your dba has set up for your Oracle instance is the "orcl" bit...make sure that it is indeed the SID (probably is, since you were able to connect to the db).

Expert Comment

ID: 2771717
rrasmussen changed the proposed answer to a comment

Author Comment

ID: 2772427
rrasmussen, thanks for answering -
I have verified the SID and your tip was good!
I am now getting
"Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135290880)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))"
and I was wondering what's that...
Do u know? The login is 100% correct and so is the connection string.

Expert Comment

ID: 2773377
Hi itailevitan.  The error your getting has the following description:

ORA-12505:  Listener could not resolve SID given in connect descriptor

Here's what I'd recommend.  If you have Oracle8 Net8 Easy Config installed on your machine, go in and set up a new configuration called TEST.  Just follow the wizard, and use EXACTLY the same values as you used for your JDBC URL above after the @.  So looking at my example above, the server name would be, the listener port would be 1521, and the SID would be orcl.  Once you've done that, the last step is to test your connection (be sure to hit the "change login" button and enter the user name and password you used in the getConnection method).  I would expect you to get a 12505 error when you attempt the connection.  If you do, then we've confirmed that you have an invalid SID.

That should give you enough ammunition to get your DBA to help you out ;-).

If he won't help you, then ask him/her to send you his/her tnsnames file and you can look at it in notepad and figure out what the correct SID is.

Author Comment

ID: 2774501
rrasmussen - thanks for hanging in there!
   I can not get help of the DBA (he's out untill Sunday - too bad for me, but I have you!) We are advancing... I did what you said: connected through Oracle8 Net8 Easy Config (after I checked the HOST, PORT and SID (SERVICE_NAME) in the tnsnames file (located on my local disk)). Guess what? I was trying to connect to an alias of the host and the host I had in my java application was not the same as HOST in the tnsnames file.
   Wait... now I am getting something strange... and I suspect that there is a driver problem. Before I explain this I want to show you what I found on the net regarding a similiar problem (it's a remark made by someone named Eric):
"In any case (even if you run it from the AIX host), make sure you have
loaded the oracle driver (you can debug the client and do a step into driver
manager code and see how it iterates over the loaded drivers). -Eric."
   Well, my application is iterating over the following:
and then my app goes to the famous line:
catch (SQLException sqle)...
.... and the message is:
"Io exception: Connection refused(DESCRIPTION=(TMP=)(VSNNUM=135290880)(ERR=12505)(ERROR_STACK=(ERROR=(CODE=12505)(EMFI=4))))"

*Rellevant info:
I downloaded Oracle8i 8.1.6 JDBC Drivers for use with JDK 1.2.x (I have the JDK 1.2.2 installed) from
here is the link info:
JDBC-Thin, 100% Java </software/htdocs/devlic.htm> (, 1.5MB)
I downloaded the file and put it in my classpath. To verify -
I unzipped the file into a temp directory to see what it contains - and it does hold all the src files as listed above (what the driver manager iterates over).

* BTW (just for curiousity) - another strange thing is that if I debug for the second time (even after changing code (without changing program's functionality ofcourse)) the Visual J++ does not iterate over the above list, unless I restart it...the Visual probably rememebers that it iterated...
*After the restart - once I start debugging again - stepping into the getConnection() method iterates in the same manner, according to the list.

.... What's next dear tutor? Is there some special driver I need to add to my classpath or something?
    And again - thank-you very much!

Expert Comment

ID: 2774640
Sounds like your classpath is fine.

Before we go further, let me ask you this:  can you connect to your database instance using SqlPlus?

According to the Oracle documentation, this is the cause of your problem:

PROBLEM:  When trying to connect to a database, you may get the message ORA-1034: "Oracle Not Available", or ORA-12505: "Listener could not resolve SID given in connect descriptor".  

WORKAROUND:  The database is not running on the server machine. A listener alone does not provide a database connection; the database instance must also be started.  

Which makes me think either something in your connect string is bogus or Oracle isn't started.  If you can log onto your Oracle instance through SQLPlus, then we can eliminate some of the unknowns and we'll know to look elsewhere.

I run NT on my machine, and just stepped through a getConnection call in J++.  Here are the first few classes Oracle uses:


As far as wierdness in J++ debugging goes, I've had the same experience.  When you are debugging and it prompts you for the source of an invoked class and you hit the cancel button, J++ remembers and doesn't ask you again.  Sort of a feature, I'd say ;-)

Author Comment

ID: 2780044
  OK rrasmussen - the goal is achieved! And its thanks to you and another friend I consulted. You said -
"Which makes me think either something in your connect string is bogus or Oracle isn't started"
well my friend, let me complament your analitical ability (and your patience and ability to explain, which is not less important) - you were right.
   The SID was wrong. I beleived the  programmmer here at my work, that told me the SID (and it made sense because the SERVICE_NAME value in the tsnames.ora file was also of that String value) - but it wasn't. Well, I've learned a lot (this is my first trial in data base connection) and that's what's important now - I thank you again. BTW my e-mail is if you want to keep in touch here and there (the experts-exchange people won't like that - but we can't have everything dictated to us in life, can we?). Please submit an answer, so I can give you the points. Stay healthy  ;-)

Accepted Solution

rrasmussen earned 100 total points
ID: 2780217
Excellent, itailevitan!  I hope you find the java.sql package fun to work with.  Your life will likely improve when the DBA gets back on Monday :~)

I'm new to the whole experts-exchange thing and don't care much about points, but feel free to give them to me.

Happy coding.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question