This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JDBC and the fly likes JDBC Connectivity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connectivity" Watch "JDBC Connectivity" New topic
Author

JDBC Connectivity

Swaminathan Ramanathan
Greenhorn

Joined: Sep 23, 2000
Posts: 8
Hello Everyone !
I'm trying to connect to Oracle from Java. I've given my coding below. But i get an error. The error is " Connection Refused No further Information". How do go about now ? Is my coding alright ? I set my classpath to c:\orawin95\jdbc\lib\classes111.zip [ i have one more zip file there in the lib folder by name classes102.zip ]. I have both jdk1.2.2 and 1.3. But here i used 1.2.2. I use Oracle 8.0.3. Somebody help me out of this prob.
This is the coding i used :
import java.sql.*;
import java.io.*;
import java.util.Date;
class JdbcTest
{
public static void main (String args [])
throws SQLException, IOException
{
System.out.println ("Loading Oracle driver");
try
{
Class.forName ("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException e)
{
System.out.println ("Could not load the driver");
e.printStackTrace ();
}
System.out.println ("Connecting to the local database");
Connection conn = null;
try {
conn =
DriverManager.getConnection
("jdbc racle:thin:scott/tiger");
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}

Statement stmt = conn.createStatement ();
// Query the employee names
ResultSet rset = stmt.executeQuery ("select ename from emp");
while (rset.next ())
{
// Print the name out
System.out.println (rset.getString (1));
}
}
}


Is there any problem with my connection specification like the thin driver ? Do help me.
Thanks and Regards.
Swamy

[This message has been edited by Swaminathan Ramanathan (edited January 22, 2001).]
Kevin Mukhar
Ranch Hand

Joined: Nov 28, 2000
Posts: 83
To use the thin driver, there must a database listener configured and listening. See http://technet.oracle.com/doc/oracle8i_816/network.816/a76933/listener.htm#475293
The other thing that appears to be wrong is the database url. In addition to the username and password, the url for a thin driver needs to include the host and port:
jdbcracle:thin:scott/tiger@host:1521:sid
Where host is the name of the machine where the database listener is listening for connections and sid is the System Identifier for the database. See http://technet.oracle.com/doc/oracle8i_816/java.816/a81354/basic1.htm#1004483
Also, while you can use classes111.zip with jdk1.2, you should probably upgrade to classes12.zip.
 
GeeCON Prague 2014
 
subject: JDBC Connectivity