This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JDBC and the fly likes Cofiguring JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Cofiguring JDBC" Watch "Cofiguring JDBC" New topic
Author

Cofiguring JDBC

vijay malhotra
Greenhorn

Joined: Nov 26, 2000
Posts: 26
I am unable to connect my java application to Personal Oracle8 database.
I am working on the windows platform.
I have installed JDBC OCI and THIN drivers.
Oracle is installed at D:\orawin
Using java 1.3
Please send me the simple java code which connects to Oracle
database and retrieves list of Employee names from Employee table.
Tell me how to configure JDBC so that java application is able
to connect to Oracle database ?
What all should be added in the autoexec.bat file. How the confiurigation
is to be done.
In the getConnection statement what path is to be given to connect to
the database ?
Please explain the procedure step by step.

Some More details are as under:-
Following is the Error Reported when I Execute the program:-
Exception in thread "main" java.sql.SQLException: Connection refused: no further
information
at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:228)
at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:100)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:147)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Employee.main(Employee.java:21)
Following is the Java Code I am using :-
/*
* This sample shows how to list all the names from the EMP table
*
* It uses the JDBC OCI8 driver. See the same program in the
* thin or oci7 samples directories to see how to use the other drivers.
*/
// You need to import the java.sql package to use JDBC
import java.sql.*;
class Employee
{
public static void main (String args [])
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc:Oracle:thin:@localhost:1521:local", "scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}
Following are the contents of autoexec file:-
SET path=C:\windows;C:\windows\command;.;c:\jdk1.3\bin;c:\jdk1.3\lib;C:\Progra~1\JavaSoft\JRE\1.3bin;
D:\ora\bin;D:\Ora\jre11\bin
set CLASSPATH=.;C:\jdk1.3\lib\;C:\jdk1.3\lib\tools.jar;D:\ora\jdbc\lib\classes111.zip
set TOMCAT_HOME=c:\tomcat
set JAVA_HOME=c:\jdk1.3
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
It might just be me, but you said Oracle was installed at D:\orawin, but in your PATH and CLASSPATH statements you are specifying D:\ora...
------------------
I'm a soldier in the NetScape Wars...
Joel


Wait a minute, I'm trying to think of something clever to say...<p>Joel
vijay malhotra
Greenhorn

Joined: Nov 26, 2000
Posts: 26
Well the oracle is installed at location
location :- D:\ora
I wrote D:\orawin by mistake , Sorry
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Cofiguring JDBC
 
Similar Threads
Set classpath problem (Oracle9.01)
JDBC
Kindly let me know to run this particular problem relating JDBC Thin Drivers
JDBC and Oracle Host
excepttion in thread "main" java.sql.SQLException: Io exception: The Network Adapter