Using Oracle11g JDBC


  1. Check the JDBC Help Pages.

  2. Login into the Server shell.
  3. You may use an SSH client such as PuTTY to access the shell.


  4. Modify the .profile File.
  5. .profile is the shell startup file and gets executed whenever you login into shell. To use Oracle JDBC, you need to set environment variables in ~/.profile file by including the following commands:

    ~/.profile
    CLASSPATH=.:/home/project/oracle/OraHome1/jre/1.1.8
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/jlib
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/jdbc/lib/classes12.zip
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/jdbc/lib/nls_charset12.zip
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/sqlj/lib/runtime.zip
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/sqlj/lib/translator.zip
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/ord/jlib
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/ord/ts/jlib
    CLASSPATH=$CLASSPATH:/home/project/oracle/OraHome1/rdbms/jlib
    CLASSPATH=$CLASSPATH:/usr/j2se/bin
    
    export CLASSPATH
    export ORACLE_SID=orcl
    export ORACLE_HOME=/home/project/oracle/OraHome1
    export DBPASS=database
    export PATH=${PATH}:/home:/usr/bin:/usr/java/bin:/usr/java/sdk/bin

    After changing the .profile file, you may exit the shell and re-enter it to have the environment variables and shell options set.

  6. Create a JDBC Program.
  7. For example, create a program named MyJDBC.java . Two sample JDBC programs can be found from EnterCustomer.java and ListCustomers.java.

  8. Compile and Run the Program.
  9. Assume the Java compiler creates a class JDBCTest.class,
      shell> /usr/bin/javac MyJDBC.java
      shell> /usr/bin/java  JDBCTest
    where the Java compiler and interpreter are located at
    shell>

    shell>