Skip Headers
Oracle® Database 2 Day + Java Developer's Guide
11g Release 1

Part Number B28765-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

2 Getting Started with the Application

To develop a Java application that connects to Oracle Database, you need to ensure that certain components are installed as required. This chapter covers the following topics:

What You Need to Install

To be able to develop the sample application, you need to install the following products and components:

The following subsections describe these requirements in detail.

Oracle Database Server

To develop the Java application, you need a working installation of Oracle Database Server with the HR schema, which comes with the database. If you choose to install the client, then you must install the Oracle Database Server before the Oracle Database Client installation. The installation creates an instance of Oracle Database and provides additional tools for managing this database. The server installation is platform-specific. For more information, refer to the following Oracle Database installation guides and release notes:

Modifying the HR Schema for the JDBC Application

The HR user account, which owns the sample HR schema used for the Java application in this guide, is initially locked. You must log in as a user with administrative privileges (SYS) and unlock the account before you can log in as HR.

If the database is locally installed, use the command prompt or console window to unlock the account as follows:

  1. Log in to SQL*Plus as a user with DBA privileges, for example:

    > SQLPLUS SYS/ORACLE AS SYSDBA
    
    
  2. Run the following command:

    > ALTER USER HR ACCOUNT UNLOCK;
    
    OR
    
    > ALTER USER HR IDENTIFIED BY HR;
    
    
  3. Test the connection as follows:

    > CONNECT HR/HR
    
    

You should see a message indicating that you have connected to the database.

Note:

For information on creating and using secure passwords with Oracle Database, refer to Oracle Database Security Guide.

In addition, some of the constraints and triggers present in the HR schema are not in line with the scope of the Java application created in this guide. You must remove these constraints and triggers as follows using the following SQL statements:

DROP TRIGGER HR.UPDATE_JOB_HISTORY;
DROP TRIGGER HR.ADD_JOB_HISTORY;
DROP TRIGGER HR.SECURE_EMPLOYEES;
ALTER TABLE EMPLOYEES  DROP CONSTRAINT JHIST_EMP_FK;
DELETE FROM JOB_HISTORY;

Oracle Database Client

Oracle Database Client installation is optional, but recommended. Installing Oracle Database Client on any computer allows easy access from that system to the Oracle Database. The installation also includes the following development tools:

  • Oracle JDBC drivers

  • Oracle Open Database Connectivity (ODBC) driver

  • Oracle Provider for OLE DB

  • Oracle Data Provider for .NET (ODP.NET)

  • Oracle Services for Microsoft Transaction Server

The client installation is platform-specific. Refer to the following Oracle Database Client installation guides for more information on installing the client:

J2SE or JDK

To create and compile Java applications, you need the full Java 2 Platform, Standard Edition, Software Development Kit (J2SE SDK), formerly known as the Java Development Kit (JDK). To create and compile applications that access databases, you must have the full JDBC API that comes with J2SE. This download also includes the Java Runtime Environment (JRE).

Note:

  • Oracle Database does not support JDK 1.2, JDK 1.3, JDK 1.4, and all classes12*.* files. You need to use the ojdbc5.jar and the ojbc6.jar files with JDK 5.n and JDK 6.n, respectively.

  • The oracle.jdbc.driver.* classes, the ojdbc4.jar file, and the OracleConnectionCacheImpl class are no longer supported or available.

  • JDK versioning conventions have changed from JDK version 1.n to JDK n. Refer to the Sun Java site at the following location for more information:

    http://java.sun.com/j2se/1.5.0/docs/relnotes/version-5.0.html

See Also:

Integrated Development Environment

For ease in developing the application, you can choose to develop your application in an integrated development environment (IDE). This guide uses Oracle JDeveloper to create the files for this application. For more information on installing JDeveloper, refer to Installing Oracle JDeveloper.

Web Server

The sample application developed in this guide uses JavaServer Pages (JSP) technology to display information and accept input from users. To deploy these pages, you need a Web server with a servlet and JSP container, such as the Apache Tomcat application server.

This guide uses the embedded server in JDeveloper for deploying the JSP pages. It is called the Oracle Application Server Containers for J2EE server, or the OC4J server for short. If you choose not to install Oracle JDeveloper, then any Web server that allows you to deploy JSP pages should suffice.

JDeveloper supports direct deployment to the following production application servers:

  • Oracle Application Server

  • BEA WebLogic

  • Apache Tomcat

  • IBM WebSphere

  • JBoss

For more information about these servers, please refer to vendor-specific documentation.

Verifying the Oracle Database Client Installation

Oracle Database client installation is platform-specific. You need to verify that the client installation was successful before you proceed to create the sample application. This section describes the steps for verifying an Oracle Database client installation.

Verifying a client installation involves the following tasks:

Checking Installed Directories and Files

Installing Oracle Java products creates the following directories:

  • ORACLE_HOME/jdbc

  • ORACLE_HOME /jlib

Check if the directories described in Table 2-1 have been created and populated in the ORACLE_HOME directory.

Table 2-1 Directories and Files in the ORACLE_HOME Directory

Directory Description

/jdbc/lib

The lib directory contains the ojdbc5.jar and ojdbc6.jar required Java classes. These contain the JDBC driver classes for use with JDK 5 and JDK 6.

/jdbc/Readme.txt

This file contains late-breaking and release-specific information about the drivers, which may not have been included in other documentation on the product.

/jlib

This directory contains the orai18n.jar file. This file contains classes for globalization and multibyte character sets support.


Note:

These files can also be obtained from the Sun Microsystems Web site. However, it is recommended to use the files supplied by Oracle, which have been tested with the Oracle drivers.

Checking the Environment Variables

This section describes the environment variables that must be set for the JDBC Thin Driver. You must set the classpath for your installed JDBC Thin Driver. For JDK 5, you must set the following values for the CLASSPATH variable:


ORACLE_HOME/jdbc/lib/ojdbc5.jar
ORACLE_HOME/jlib/orai18n.jar

Ensure that there is only one JDBC class file, such as ojdbc6.jar, and one globalization classes file, orai18n.jar, in the CLASSPATH variable.

Determining the JDBC Driver Version

Starting from Oracle Database 11g Release 1, you can get details about the JDBC support in the database as follows:

> java -jar ojdbc6.jar
  Oracle 11.1.0.0. JDBC 4.0 compiled with JDK6

In addition, you can determine the version of the JDBC driver that you installed by calling the getDriverVersion method of the OracleDatabaseMetaData class.

Note:

The JDBC Thin Driver requires a TCP/IP listener to be running on the computer where the database is installed.

Example 2-1 illustrates how to determine the driver version:

Example 2-1 Determining the JDBC Driver Version

import java.sql.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.OracleDataSource;

class JDBCVersion
{
  public static void main (String args[]) throws SQLException
  {
    OracleDataSource ods = new OracleDataSource();
    ods.setURL("jdbc:oracle:thin:hr/hr@localhost:1521/XE");
    Connection conn = ods.getConnection();

    // Create Oracle DatabaseMetaData object
    DatabaseMetaData meta = conn.getMetaData();

    // gets driver info:
    System.out.println("JDBC driver version is " + meta.getDriverVersion());
  }
}

Installing Oracle JDeveloper

In this guide, the integrated development environment (IDE) that is used to create the sample Java application using JDBC is Oracle JDeveloper release 10.1.3. This release of JDeveloper is supported on the Microsoft Windows XP, Windows 2000, Windows NT, Linux, Solaris, Mac OS X, and HP-UX operating systems. Installation of JDeveloper is described in detail in Oracle JDeveloper 10g Release 3 (10.1.3) Installation Guide for the Studio Edition, which is available online on the Oracle Technology Network at

http://www.oracle.com/technology/documentation/jdev/1013install/install.html

This guide gives a detailed description of the JDeveloper system requirements, and all the details about installing JDeveloper on the supported platforms. You should also read JDeveloper 10g Release Notes, which is available online on the Oracle Technology Network at

http://www.oracle.com/technology/products/jdev/htdocs/10.1.3.0.3/readme.html

JDeveloper Studio Edition: Base Installation and Full Installation

JDeveloper 10.1.3 is available in three editions. Further, each of these editions is available as the base installation and the full installation. The Studio Edition includes Oracle ADF, which is required for developing the master-detail application created in this guide.

You can install either the base installation or the full installation of the JDeveloper Studio Edition. In addition to JDeveloper, the full installation includes the required version of Java, the specialized Oracle Java Virtual Machine for JDeveloper (OJVM), and the online documentation, so the download file size is larger. For quicker downloading, you can install the JDeveloper base installation.

Steps to Install JDeveloper

JDeveloper does not require an installer, because it is provided as a ZIP file. In outline, the installation process is as follows:

  1. If you are installing the Base version, you need to have J2SE version 1.5.0_05 on your machine. If you are installing the Full version, this J2SE is included.

  2. Download JDeveloper version 10.1.3 Studio Edition from the Oracle Technology Network at

    http://www.oracle.com/technology/software/products/jdev/htdocs/soft1013.html

    Download the base installation (jdevstudiobase1013.zip), or the full installation (jdevstudio1013.zip)

  3. Unzip the downloaded file into a target installation directory.

    Note:

    Do not install JDeveloper in any existing ORACLE_HOME. You will not be able to uninstall it using Oracle Universal Uninstaller.

    If you install jdevstudio1013.zip on a UNIX or Linux system, you have to modify jdev.conf to specify the SDK. Set the variable SetJavaHome in the file <jdev_install>/jdev/bin/jdev.conf to the location of your Java installation.For example, in a UNIX environment, if the location of your Sun J2SE SDK is in a directory called /usr/local/java, your entry in jdev.conf would be as follows:

    SetJavaHome /usr/local/java

    Other tasks that you must perform include setting the permissions for all JDeveloper files to read, and giving all users write and execute permissions to files in a range of JDeveloper directories.

  4. If you are using the base installation, there are some additional setup tasks, such as setting the location of your Java installation in the JDeveloper configuration file, optionally installing OJVM, and downloading the online documentation so that it is locally available.

Starting JDeveloper

To start JDeveloper on Windows, run the jdev_install\jdev\bin\jdevw.exe file, where jdev_install is the path to the location where you extract the JDeveloper files. To use a console window for displaying internal diagnostic information, run the jdev.exe file in the same directory instead of jdevw.exe.

To start JDeveloper on other platforms, run the jdev_install/jdev/bin/jdev file.