Link to home
Start Free TrialLog in
Avatar of itailevitan
itailevitan

asked on

Trying to connect to Oracle!!!

1) I have installed Oracle client(releas 8.1.5) on my WIN98.

2) I am able to connect to a dsn called "dev.web.com" 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 dev.web.com. 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 dev.web.com) through my java application. The rellevant code for loading the driver and for getting the connection is the following:

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

public class oracleConnectTrial
{
  public void selectData()
  {
    Connection con = null;            
            
    try
    {
     // Load the Driver class file
     Class.forName
     ("sun.jdbc.odbc.JdbcOdbcDriver");
                  
//Make a connection to the ODBC datasrc
con = DriverManager.getConnection("jdbc:odbc://dev.web.com", "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.
Avatar of Laminamia063099
Laminamia063099

If you've set up the ODBC on your machine with the service name of dev.web.com, then your getConnection statement should work with:

con = DriverManager.getConnection("jdbc:odbc:dev.web.com", "usr", "pass");

You don't need the '//'.
If you have any more trouble, drop another comment and I'll be glad to help.

Laminamia :)
Avatar of itailevitan

ASKER

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?
Laminamia changed the proposed answer to a comment
I tried changing the driver. Here is the code and the SQLException message-

// Load the Driver class file
Class.forName("oracle.jdbc.driver.OracleDriver");
                  
// Make a connection to the data base
con = DriverManager.getConnection("jdbc:oracle:thin:@dev.web.com:1521:orcl", "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?!
10'x!
      
I would guess that your problem revolves around your connect string.  Specifically, you stated above that you created a Microsoft DSN called dev.web.com, as well as an entry in your TNSNames file called dev.web.com.

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 dev.web.com, 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@192.192.192.192:1521:orcl","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).
rrasmussen changed the proposed answer to a comment
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.
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 192.192.192.192, 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.
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:
                OracleDriver.java
                TTC7Protocol.java
                DBAccess.java
                OracleConnection.java
                OracleLog.java
                DBError.java
                SQLStateMapping.java
                SQLStateRange.java
                Message11.java
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
http://technet.oracle.com/software/tech/java/sqlj_jdbc/software_index.htm
here is the link info:
JDBC-Thin, 100% Java </software/htdocs/devlic.htm> (classes12.zip, 1.5MB)
I downloaded the classes12.zip file and put it in my classpath. To verify -
I unzipped the classes.zip 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!
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:

TTC7Protocol
DBAccess
OracleConnection
NSProtocol
SessionAtts
AddrResolution
ClientProfile
ConnStrategy
ConnOption

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 ;-)
  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 itailevitan@hotmail.com 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  ;-)
ASKER CERTIFIED SOLUTION
Avatar of rrasmussen
rrasmussen

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial