Solved

Trying to connect to Oracle!!!

Posted on 2000-05-02
13
358 Views
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 "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.
0
Comment
Question by:itailevitan
  • 5
  • 5
  • 3
13 Comments
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2770003
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 '//'.
0
 
LVL 3

Expert Comment

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

Laminamia :)
0
 

Author Comment

by:itailevitan
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?
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2770229
Laminamia changed the proposed answer to a comment
0
 

Author Comment

by:itailevitan
ID: 2770474
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!
      
0
 

Expert Comment

by:rrasmussen
ID: 2771688
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).
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Expert Comment

by:rrasmussen
ID: 2771717
rrasmussen changed the proposed answer to a comment
0
 

Author Comment

by:itailevitan
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.
0
 

Expert Comment

by:rrasmussen
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 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.
0
 

Author Comment

by:itailevitan
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:
                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!
0
 

Expert Comment

by:rrasmussen
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:

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 ;-)
0
 

Author Comment

by:itailevitan
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 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  ;-)
0
 

Accepted Solution

by:
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now