Date Sample Application
Table Of Contents
This sample application illustrates the use of
DATE data type access through JDBC calls. It simulates an Order
Delivery system in which the proposed and the actual delivery
dates of goods are tracked by the application. The user can add
new orders with the proposed delivery date and at a later point
of time update this record with the actual delivery date. The orders
are listed for the user to browse/update.
Working of the Sample
The sample application uses a database table
OTN_DELIVERYDETAILS. When
the application is invoked, the table is created if it does not
exist. The status of the connection is shown in the status bar. Errors
if any, are shown in the status bar.
Pressing the 'New' button can create New order.
Order Id and the Proposed Delivery Date needs to be entered
mandatorily. The Actual Delivery Date value is optional. The
news order can be persisted in the database by pressing the 'Add'
button. Only the Actual Delivery Date for the existing Orders
can be updated.
Here is the code usage for inserting an Order into the database.
You can find more details of the code in DateSample.java file under src/oracle/otnsamples/jdbc/datetype folder.
Look into Description of Sample Files
section for folder and file details.
public void insertDeliveryData( ) { PreparedStatement pstmt = null; ......... ......... try { pstmt = conn.prepareStatement( "INSERT INTO otn_DeliveryDetail "+ " VALUES( ?,?,? ) " ); pstmt.setInt( 1, gui.getOrderId( ) );
// Set the proposed delivery date pstmt.setDate( 2, proposedDate );
// If actual delivery date is blank or invalid, // insert NULL instead if( actualDate == null ) // Insert null for actual date pstmt.setNull( 3, Types.DATE); else // Set the actual delivery date pstmt.setDate( 3, actualDate ); // Execute the statement int rows = pstmt.executeUpdate( ); ........... ...........
|
- Oracle9i
JDeveloper ( Note: Oracle9i
JDeveloper is Oracle's Visual Java Development Tool and can be
downloaded from here)
or JDK1.2.x or above This can be downloaded from here.
- Oracle9i
Database or higher running SQL*Net TCP/IP listener. This can be
downloaded from here.
- Oracle9i
JDBC Driver. This can be downloaded from here.
- Unjar the provided DateSample.jar
using the following command
> jar xvf DateSample.jar
Note: You will find jar.exe in JDK_HOME\bin.
Ensure JDK_HOME\bin is present in your system path.
(JDK_HOME is the root directory of the JDKx.x installation).
This creates a folder DateSample with all the source files.
- Edit DateSample/Connection.properties file in your favorite editor. Change the HostName,
Port, SID, UserName and Password to connect to your own database.
| HostName |
= |
incq212e.idc.oracle.com |
| SID |
= |
otn9i |
| Port |
= |
1521 |
| UserName |
= |
scott |
| Password |
= |
tiger |
This sample application can be run in 3 different
ways listed below.
From Oracle9i JDeveloper
- Open Oracle9i JDeveloper and use File/Open option to select the DateSample.jws from
the DateSample
directory.
- Next, select Project/Make DateSample.jpr from main menu.
- Now, select Run/Run
DateSample.jpr from main menu to run the application.
From JDK for Windows
This section will describe steps to run
the application from console using JDK on Windows. The sample
can be run either manually or using a script file .
Run application
using batch File: run.bat provided:
By setting few environment variables,
the sample application could be directly run by just executing
the batch file: run.bat from the command
prompt, from DateSample directory. Environmental variables JAVA_HOME and JDBC_HOME have to be set before running run.bat file.
Example:
D:\DMLSample> set JDBC_HOME=d:\oracle9i\jdbc\lib
D:\DMLSample> set JAVA_HOME=d:\jdk1.3.1
D:\DMLSample> run
Running the application
manually:
-
Set CLASSPATH to include
Oracle9i JDBC Driver file: classes12.zip
- DateSample
directory where Connection.properties exists and current directory are also added
to the CLASSPATH
Example:
D:\DateSample>set CLASSPATH=D:\oracle9i\jdbc\lib\classes12.zip;D:\DateSample;.
- Make sure that Java is in the PATH
Example: D:\DateSample>set PATH=.;d:\jdk1.3.1\bin;%PATH%
- From the directory DateSample\src\oracle\otnsamples\jdbc\datetype, compile all the java files using javac:
Example:
D:\DateSample\src\oracle\otnsamples\jdbc\datetype>javac
-d . *.java
- Run the class file using java
from the same DateSample\src\oracle\otnsamples\jdbc\datetype directory
Example:
D:\DateSample\src\oracle\otnsamples\jdbc\datetype>
java oracle.otnsamples.jdbc.datetype.DateSample
From JDK for Red Hat Linux Advanced Server release 2.1
This section will describe steps to run
the application from console using JDK on Linux. The sample can
be run either manually or using a script file .
Run application
using batch File: run.sh provided:
By setting few environment variables,
the sample application could be directly run by just executing
the batch file: run.sh from the command
prompt, from DateSample directory.
Environmental variables JAVA_HOME
and JDBC_HOME have to be set,
else the user will be prompted to enter values.
- Go to DateSample directory
and from the $
prompt use the command below to give execute permission to
the file.
$chmod 777 run.sh
- Now run the file:
$sh run.sh
Running the application
manually:
The directory structure of the deliverable DateSample.jar will be as shown below. DateSample is
the top level directory
|
Directory
|
Files
|
Description
|
| DateSample |
DateSample.jws |
The Oracle9i JDeveloper workspace file. |
| DateSample.jpr |
The Oracle9i JDeveloper project file. |
| Connection.properties |
This file has the details
of the database connection parameters. |
| run.bat |
The batch file to compile
and run the sample in Windows environment. |
| run.sh |
The batch file(shell script)
to compile and run the sample in Linux environment. |
| DateSample\doc |
Readme.html |
This file. |
| DateSample\src\oracle\otnsamples\jdbc\datetype |
DateSample.java |
The source file for sample. |
| DateFrame.java |
The source file for the sample
User Interface. |
|