Solved

JDBC Oracle connection in java

Posted on 2007-03-19
7
641 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
[X]
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
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 48

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: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.
0
 
LVL 48

Expert Comment

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

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

630 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