• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Cofiguring JDBC

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
vijay malhotra
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well the oracle is installed at location
location :- D:\ora
I wrote D:\orawin by mistake , Sorry
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic