Connecting to Oracle

I am trying to connect and retrieve records from an Oracle Database, from my Java program (which is a downloaded Oracle Java Stored Procs sample from the site technet.oracle.com, the Hotel Reservation Sample).

I downloaded the 816classes12.zip from the Oracle downloads site, and put it in the classpath. i think this is Oracle JDBC Thin driver.

Here's part of the code :

import java.sql.*;  
import java.util.*;  

import oracle.sql.*;
import oracle.jdbc.driver.*;
.
.
.
Connection m_connection;  
.
.
.

Statement l_statement=m_connection.createStatement();

The program hangs at the above statement. Why is it so ?

In the DOS window, i see the msg :
java.lang.NullPointerException


I am using JDK1.2.1, is it that i do not have correct version of JDBC or what ?
Any clues...

Thanks
LVL 1
JituAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JituAuthor Commented:
1i think the connection itself is failing....because the following statement (which appears at the beginning of the program) does not return any valid value (hence the NullPointerException above!)... though i have provided it with correct s_userName, s_passwd, and l_dbConnectString


m_connection = DriverManager.getConnection(
                  "jdbc:oracle:thin:@"+l_dbConnectString,
                  ConnectionParams.s_userName,
                  ConnectionParams.s_password);

0
Ravindra76Commented:


Hi jitu,

Check your connection string value

I think there is wrong in connection string

Have written the first statement as  

1. Class.forName("oracle.jdbc.driver.OracleDriver");

2. connection = DriverManager.getConnection
             ("jdbc:oracle:thin:@"+oraIP()+":"+                                
               oraPort+":"+oraSID,
               oraLogin,
               oraPassword);


Here oraLogin     = ConnectionParams.s_userName
        orapassword = ConnectionParams.s_password

      for oraip,oraport,orasid substitue your values properly


Now Try.

Best of luck
0
JituAuthor Commented:
RAVINDRA76 >

still not successful... :-(

the exception msg is :

java.sql.SQLException : The network adapter could not establish the connection.

Any clues....
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Ravindra76Commented:

Hi Jitu,


I think your database server is in another  machine.
Am i right?

First make a ping call to the following

ping ipaddressoforacleserver ( assume 200.200.200.1)

Eg:

ping 200.200.200.1

If  request timed out exception comes, it's a network problem.
It is H/W problem related to adapter or network settings problem so that it may not reach server.

If it is succeflu, try to connect to server by oracle clinet s/w in your machine

Enter your username and password what you have given in your java code.

If it is connecting to server, the problem is definitely in your code

Check all entries of IPaddress,SID,USername,password,port

Best of luck

0
Ravindra76Commented:
Hi Jitu,

Can you post just those fourlines code


1.Loading classes

2.Creating Connection

3. Your Connection Params values

Thank you
0
JituAuthor Commented:


Loading and register JDBC driver:

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Creating Connection :

m_connection = DriverManager.getConnection             ("jdbc:oracle:thin:@SUN:1521:ORCL",
               "travel",
               "travel");

*program does not execute statements beyond this point.*

where SUN is the host name (which i use to connect via the SQL client), 1521 the port, ORCL the sid.
travel is username and passwd.

I think i must try writing a small java program to test all this separately, instead of the downloaded sample.. :-(
0
JituAuthor Commented:
Ravindra >
 
I was able to connect to the DB. The SID value that i was giving in Connection Params was wrong, hence the problem.

Thanks for pointing out those details.
Can u please post your answer again, so that i can transfer the points to you.

:-)
Jitu
0
Ravindra76Commented:

Hi Jitu,

 I am posting answer as you told

                  I think your database server is in another  machine.
                  Am i right?

                  First make a ping call to the following

                  ping ipaddressoforacleserver ( assume 200.200.200.1)

                  Eg:

                  ping 200.200.200.1

                  If  request timed out exception comes, it's a network problem.
                  It is H/W problem related to adapter or network settings problem so that it
                  may not reach server.

                  If it is succeflu, try to connect to server by oracle clinet s/w in your
                  machine

                  Enter your username and password what you have given in your java code.

                  If it is connecting to server, the problem is definitely in your code

                  Check all entries of IPaddress,SID,USername,password,port

                  Best of luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.