Java, Apache, Tomcat, Oracle Database: How to


  


IV. Installing Oracle:

IV.1. Installation:

Download Oracle Database 10g Express Edition, DO NOT INSTALL yet, just download at
Go to: 
http://www.oracle.com/technology/software/products/database/xe/index.html
Click on the “Oracle Database 10g Express Edition for Microsoft Windows” link
Click on the “OracleXE.exe” download link
The file to download is: “OracleXE.exe” (165,332,312 bytes)
Once downloaded, doubleclick on the “OracleXE.exe” to start the installation.

The installation is done on: C:\oraclexe
Set the oracle_home:
Sittings - Control Panel - System - Advanced - Environment Variables, and then:
ORACLE_HOME C:\oraclexe\app\oracle\product\10.2.0\server

Now, the CLASSPATH setting is as follows:
.;C:\Program Files\Java\jre1.6.0_01\lib\ext\QTJava.zip;
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar


Oracle will appear in localhost:8080
(if you set yes during the installation). To transfere it at localhost:15:
1. Run SQL Command Line from:
start - programs - Oracle database 10g Express Edition
2. Connect to Oracle Database:
SQL> connect
Enter user-name: System
Enter password: ******
Connected.
3. We have :
 select dbms_xdb.gethttpport as "HTTP-Port", dbms_xdb.getftpport as "FTP-Port" from dual;

 HTTP-Port   	  FTP-Port
 ----------             ----------
      8080            0

4. Change http and ftp ports as follows:
SQL> -- set http port and ftp port
SQL>  begin
  2  dbms_xdb.sethttpport ('1521');
  3  dbms_xdb.setftpport ('1520');
  4  end;
  5  /

PL/SQL procedure successfully completed.

5. Check if everything is ok:
SQL> select dbms_xdb.gethttpport as "HTTP-Port", dbms_xdb.getftpport as "FTP-Port" from dual;

 HTTP-Port     FTP-Port
  ----------          ----------
      1521         1520

SQL> quit

From now on Oracle Database runs on http://localhost:1521/


IV.2. Set the oracle jdbc package:

Next, to connect to Oracle Database, we need the 
JDBC(Java DataBase Connctivity); that is is an application programming 
interface (API) to access SQL data.
Go to:
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_10201.html
and dowload  ojdbc6 or ojdbc6_g and put it in the installation directory like: 
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib
Set the class_pah:
CLASSPATH C:/oraclexe/app/oracle/product/10.2.0/server/jdbc/lib/ojdbc6.jar

Finaly, the CLASSPATH setting is as follows:
CLASSPATH: .;C:\Program Files\Java\jre1.6.0_01\lib\ext\QTJava.zip;
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc6.jar




IV.3. Test the connectivity:

IV.3.1. Preface:
JDK1.6, Oracle 10g 2(10.2.0.1.0), and jdbc6 do not work, because the installled oracle 
version do not mach (JDK, and jdbc5 or jdbc6). Down grade in this case.

The version of Oracle installed is: Oracle Databse 10g Release 2(10.2.0.1.0). For this 
release, there is not a driver jdbc related to JDK1.6, but there is one corresponding 
to ojdbc14.jar related to JDK1.5. Foretheremore:
Oracle 10g 2(10.2.0.1.0), JDK1.5, and ojdbc14.jar work fine. 
From now on, to connect to Oracle database. JDK1.5 is used.

The related classpath is then:
CLASSPATH =.;C:\Program Files\Java\jre1.5.0_14\lib\ext\dnsns.jar;
C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar;
C:\oraclexe\app\oracle\product\10.2.0\server\jlib\orai18n.jar

IV.3.2. Examples:
a. First application: Get connection:

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.OracleDriver;

  public class OracleConnect
  {
    public static void main(String[] args)throws SQLException
    {
      try
      {
        Class.forName("oracle.jdbc.driver.OracleDriver");	
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@HOST:1521:XE","User","Password");
		if(conn != null)
		{ System.out.println("I am Connected to oracle database");
			}
        conn.close();
      } catch (Exception e) {
        System.out.println("ERROR : " + e);
        e.printStackTrace(System.out);
      }
    }
  }

b. Second application: Test connection, question a built Students database:

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.OracleDriver;	
	
public class showTable{
  public static void main (String args []) throws SQLException
  {
     DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@HOST:1521:XE","User","Password");		
		Statement stmt = conn.createStatement();
	try {
    ResultSet rs = stmt.executeQuery( "SELECT * FROM Students WHERE STUDENTID ='103' " );
    try {
        while ( rs.next() ) {
            int numColumns = rs.getMetaData().getColumnCount();
            for ( int i = 1 ; i <= numColumns ; i++ ) {//Column numbers start at 1.
               System.out.println( "COLUMN " + i + " = " + rs.getObject(i) );
            }
		System.out.println();
        }
    } finally {
        rs.close();
    }
} finally {
    stmt.close();
	}
  }
}// End of class

Custom Java Search


© The Scientific Sentence. 2007 -     Contents -     home