1 Reply Latest reply: Apr 18, 2012 2:55 PM by Brian Bontrager RSS

    connect to a 0racle sever from a client  without installing oracle client

    926542
      Hi,
      I am try connect to a oracle database srver(10g) from a client mechine without installing oracle client.

      /* This class demonstrates how to connect to a database using DriverManager.
      * COMPATIBLITY NOTE: tested against 10.2.0.1.0. */
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.SQLException;
      import java.sql.Statement;
      import java.sql.ResultSet;
      import java.lang.Class;
      import oracle.jdbc.OracleDriver;

      class JDBCOldStyleConnectionOci
           {
           public static void main (String args[])
                {
                try
                     {
                     DriverManager.registerDriver( new OracleDriver());
                     //Class.forName ("oracle.jdbc.OracleDriver").newInstance();
                     System.out.println ("Register the driver..........? OK " );
                     }
                catch (SQLException e)
                     {
                     // handle the exception properly - in this case, we just
                     // print a message and stack trace and exit the application
                     System.err.println ("ERROR: Could not register the driver! Exiting .." );
                     e.printStackTrace();
                     Runtime.getRuntime().exit(1);
                     }
                Connection ociDriverConnection = null;
                try
                     {
                     String ociDriverURL = "jdbc:oracle:oci:@server:1521:ORCL";
                     ociDriverConnection = DriverManager.getConnection (
                     ociDriverURL, "scott", "tiger" );
                     System.out.println ("Connection to the Database.........? OK" );
                     }
                catch (SQLException e)
                     {
                     // handle the exception properly - in this case, we just
                     // print a message and stack trace and exit the application
                     System.err.println ("ERROR: Could not get connection! Exiting .." );
                     e.printStackTrace();
                     Runtime.getRuntime().exit(1);
                     }
                ResultSet rset = null;
                Statement stmt = null;
                try
                     {
                     stmt=ociDriverConnection.createStatement();
                     rset = stmt.executeQuery( "select empno, ename, job from emp" );
                     System.out.println( "empNo" + " " + "empName" + " " + "empJob" );
                     while (rset.next())
                          {
                          int empNo = rset.getInt ( 1 );
                          String empName = rset.getString ( 2 );
                          String empJob = rset.getString ( 3 );
                          System.out.println( empNo + " " + empName + " " + empJob );
                          }
                     }
                catch (SQLException e)
                     {
                     // handle the exception properly - in this case, we just
                     // print a message and stack trace and exit the application
                     System.err.println ("error message: " + e.getMessage() );
                     e.printStackTrace();
                     Runtime.getRuntime().exit(1);
                     }
                }
           }

      But when i try to compile this file getting err
      paakege oracle.jdbc does not exist.

      please help me.

      thanks