JDBC Oracle connection in java

Posted on 2007-03-19
Last Modified: 2010-05-18
I have connection to Oracle database in ASP. Now, I have problem converting to the connection to use JDBC in java. Please help shed some light.

Oracle Connection in ASP
strConn ="DRIVER={Oracle in OraHome90};DSN=<DSN>;DBQ=<DBQ>;UID=<user name>;PWD=<password>;"
Set conntemp = Server.CreateObject("ADODB.Connection")
if conntemp.state=0 then
      conntemp.Open strConn

My attempt in JDBC
String driver = "oracle.jdbc.driver.OracleDriver";

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@(description=(address=(host=<host name>)(protocol=tcp)(port=<port>))(connect_data=(sid=<sid>)))",<user name>,<password>);

When i run the connection in java, i get IOException : The network adapter could not establish the connection.

Is it because i specify the host name wrongly?

Question by:rospcc
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

Accepted Solution

mnrz earned 125 total points
ID: 18746655
@(description=(address=(host=<host name>)(protocol=tcp)(port=<port>))(connect_data=(sid=<sid>)))

host name, port and sid should be specified

LVL 92

Assisted Solution

objects earned 125 total points
ID: 18746744
LVL 48

Assisted Solution

schwertner earned 125 total points
ID: 18747273
I use this with Jdeveloper,
but before this i  place i CLASSPATH the needed
Oracle classes - this is very important

* Reading from scot/tiger table

import java.sql.*;

import oracle.jdbc.pool.OracleDataSource;

class first {
public static void main (String args []) throws SQLException {
// Create DataSource and connect to the local database
OracleDataSource ods = new OracleDataSource();
Connection conn = ods.getConnection();
// Query the employee names
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("SELECT ename FROM emp ORDER BY ename");
// Print the name out
while ( ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 125 total points
ID: 18750329
Sounds like the machine name or port number you entered in your connection string was incorrect. Are you able to connect through SQL * Plus? Your connection string could also be simplified based on what schwertner mentioned.

>> Class.forName(driver);
>> DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

The call to registerDriver () is redundant.
LVL 48

Expert Comment

ID: 18754579
Also you need in CLASSPATH variable the Oracle classes for connection to the database.

Featured Post

Industry Leaders: 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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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