[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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
0
Jitu
Asked:
Jitu
  • 4
  • 4
1 Solution
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now