JDBC 3.0 Feature: Support for IEEE datatypes BINARY_DOUBLE,
BINARY_FLOAT- Planet Distance Application Readme

Table of Contents
  1. Introduction
  2. Application Overview
  3. Sample Application Files
  4. Setting up the Sample Application

1. Introduction

Back To Top

1.1 Pre-requisites

Fundamental concepts of using and working with Java, JDBC, SQL, Oracle Database.


1.2 Technical Overview

This sample application illustrates the new JDBC 3.0 feature: Support for IEEE datatypes BINARY_DOUBLE and BINARY_FLOAT within the Oracle Database 10g as well as from the Oracle JDBC 10g.

Fundamentals of the datatypes:

BINARY_DOUBLE is a 64-bit, double-precision floating-point number datatype. Each BINARY_DOUBLE value requires 9 bytes, including a length byte. A 64-bit double format number X is divided as

sign s 1-bit
exponent e 11-bits
fraction f 52-bits

BINARY_FLOAT is a 32-bit, single-precision floating-point number datatype. Each BINARY_FLOAT value requires 5 bytes, including a length byte. A 32-bit single format number X is divided as

sign s 1-bit
exponent e 8-bits
fraction f 23-bits

In a NUMBER column, floating point numbers have decimal precision. In a BINARY_FLOAT or BINARY_DOUBLE column, floating-point numbers have binary precision. The binary floating-point numbers support the special values infinity and NaN (not a number).

Support from JDBC:
In order to bind a binary_float or binary_double parameter, cast the prepared statement to oracle.jdbc.driver.OraclePreparedStatement and invoke setBinaryFloat() or SetBinaryDouble(). If you instead invoke setFloat() or setDouble(), the actual data bind will be done as for a NUMBER column and there will be both loss of performance and possible data corruption.

2. Application Overview

Back To Top

For demonstrating the new IEEE datatypes: BINARY_FLOAT and BINARY_DOUBLE, the sample application will show a comparison table that displays the same data stored in BINARY_FLOAT and BINARY_DOUBLE and a normal NUMBER column. It is seen that BINARY_DOUBLE offers the highest data precision.

The sample application creates a database table: planet_au_distance that has columns of the new datatypes. The application actually uses a scenario where, the distance between the Sun and different planets in our Solar System is expressed in terms of Astronomical Unit.

1 Astronomical Unit (AU) = 149600000 Kilometers; the average distance between the Sun and the Earth.

For example, the average distance between Mercury and Sun is 58000000 Kilometers. To gets its AU distance, the formula is: (distance in kms)/1 AU.
i.e 58000000/149600000 = 0.38770053475935828877005347593583...

The distance in terms of AU is stored in the database columns of the types: BINARY_FLOAT, BINARY_DOUBLE and NUMBER. Depending on the precision these datatypes offer, the above value is stored in the database. A clear difference in the value can be seen when these values are retrieved.

     2.1 Code Support

     Following is the code snippet from IeeeApplication.java file which demonstrates the usage of BINARY_DOUBLE and BINARY_FLOAT related APIs from the JDBC application.

    .......
    .......
    
    // OraclePreparedStatement object to execute the SQL INSERT statement.
    OraclePreparedStatement opstmt = null;
    .....

    // Create the SQL query string to select the records.
    String sqlQuery = "INSERT INTO planet_au_distance "+
                      " VALUES(?,?,?,?,?,149600000)";

    // Create the PreparedStatement object with the SQL query String.
    opstmt = (OraclePreparedStatement)conn.prepareStatement(sqlQuery);
    .......
    .......
      
    // Get the distance of the planet.
    double distance = Double.parseDouble(dist);
      
    // 1 Astronomical Unit(AU)= 149600000 Kms; avg. distance between 
    // Sun-Earth. Divide the distance by AU.
    double distVal = distance/149600000;
    Double dbl1 = new Double(distVal);     
      
    // Bind the 'BINARY_DOUBLE' datatype value.
    BINARY_DOUBLE biD = new BINARY_DOUBLE(dbl1.doubleValue());
    opstmt.setBinaryDouble(3,biD);

    // Bind the 'BINARY_FLOAT' datatype value.
    BINARY_FLOAT biF = new BINARY_FLOAT(dbl1.floatValue());
    opstmt.setBinaryFloat(4,biF);
      
    // Bind the normal 'NUMBER' datatype value.
    int biN = (int)distVal;
    opstmt.setInt(5,biN);
            
    // Execute the PreparedStatement.
    int val =opstmt.executeUpdate();

    .......
    .......

3.Sample Application Files

Back To Top

3.1 Readme file and Stylesheets

File

Description

Readme.html

This file.

Install.html

Install document to test and run the sample application.


3.2 Sample Application files

File

Description

IeeeApplication.java

Runnable Java class that demonstrates the IEEE datatypes BINARY_FLOAT and BINARY_DOBLE.

IeeeFrame.java This is a SWING frame class that displays the application GUI. The GUI has a jtable that displays records from the database table and a few buttons like 'Insert', 'Clear' and 'Exit'.
GenTableModel.java

The source file for the GenTableModel class, which handles the JTable data.

PopulateTable.java This class actually creates the database table: planet_au_distance in the database when the application is run. It creates the table if it does not exist.
Connection.properties File where database details like hostname, port, sid, username, passwords are stored. This file is read by IeeeApplication.java during execution.

run.bat

Batch file for executing the sample application automatically on the Windows platform. Make sure to set environmental variables mentioned in Install.html before this is run.

run.sh Batch file for executing the sample application automatically on the Linux platform. The script when executed will prompt the user to set environmental variables mentioned in Install.html.
UsingIEEEDataTypes.jws The Oracle9i JDeveloper workspace file.

UsingIEEEDataTypes.jpr

The Oracle9i JDeveloper project file.


4. Setting up the Sample Application

Back To Top

Please refer the Install.html for running the sample application.


Please enter your comments about this sample in the OTN Sample Code Discussion Forum.

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy