Solved

JDBC Oracle connection in java

Posted on 2007-03-19
7
621 Views
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";
Class.forName(driver);

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?

thanks
                  
0
Comment
Question by:rospcc
7 Comments
 
LVL 8

Accepted Solution

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

0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 18746744
0
 
LVL 47

Assisted Solution

by:schwertner
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();
ods.setURL("jdbc:oracle:thin:@//oralin3:1521/phr7b");
ods.setUser("scott");
ods.setPassword("tiger");
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 (rset.next ())
System.out.println (rset.getString (1));
//close the result set, statement, and the connection
rset.close();
stmt.close();
conn.close();
}
}
0
 
LVL 30

Assisted Solution

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

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

757 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

27 Experts available now in Live!

Get 1:1 Help Now