JDBC Sample Programs

JDBC is an industry standard Java API for SQL query and data management. This page provides a set of sample programs using JDBC to access the Oracle TimesTen in-memory database. See the Oracle TimesTen In-Memory Database Installation Guide for supported JDK versions.

  Program Description
 asyncJMS.java 

This program uses the TimesTen JMS/XLA implementation to process messages:

a) Connect to the database as an XLA user
b) Listen to committed changes to the CUSTOMER table
c) Use a JMS Subscriber
d) ASYNCHRONOUSLY receive messages via onMessage() and a JMS MessageListener
e) Display the change records to the console
f) Disconnect from the database when the used enters CTRL-C

Either the level1 - level4 JDBC programs or ttIsql can be used to apply committed changes to the CUSTOMER table.
 level1.java  This program uses the TimesTen JDBC DriverManager interface to show basic operations on a TimesTen database:
a) Connect using the com.timesten.jdbc.timesTenDriver interface
b) Insert into the CUSTOMER table all the data read from input file input1.dat file
c) Call ttOptUpdateStats to update statistics
d) SELECT from the CUSTOMER table, fetch, and print the result set to stdout
e) Disconnect from the database
 level2.java  This program uses the TimesTen DataSource interface to show basic operations on a TimesTen database:
a) Connect using the TimesTenDataSource interface
b) Insert all the data read from the input2.dat file located in the datfiles subdirectory
c) Call ttOptUpdateStats to update statistics
d) DELETE duplicate product data from the PRODUCT table
e) Update the PRODUCT table by increasing the product price by 10%
f) SELECT the data from the PRODUCT table, fetch and print the result set to stdout; and
g) Disconnect from the database
 level3.java  This program uses the TimesTen JDBC driver to perform order processing operations:
a) Connect to the database using the TimesTenDataSource interface
b) Process all orders in the input3.dat file by inserting into the ORDERS and ORDER_ITEM tables, select from the Inventory table to check available quantity, and update the INVENTORY table to debit the quantity from the order. If there is not enough quantity in the inventory, the program rolls back the transaction and issues the message.
c) Disconnect from the database.
 level4.java  This program is the multi-threaded version of the level3.java program. This program uses multiple threads to increase the application throughput.
  plsqlJDBC.java

This sample program uses JDBC to access common PL/SQL packages (emp_pkg and sample_pkg) in four different ways:

- Calls a stored procedure with IN and OUT parameters
- Calls a stored function with IN and OUT parameters
- Calls an anonymous block and passes host variables into and out of the block
- Calls a store procedure to open a ref cursor and uses JDBC to process the result-set of the ref cursor

The EMP table and the emp_pkg and sample_pkg PL/SQL packages need to exist for this program to work.


  syncJMS.java

This program uses the TimesTen JMS/XLA implementation to process messages:

a) Connects to the database as an XLA user
b) Listen to committed changes for ANY table (defaults to the appuser.customer table).
c) Use a JMS Subscriber
d) SYNCHRONOUSLY receive messages via the receive method in the get routine.
e) Display the change records to the console
f) Disconnect from the database when the used enters CTRL-C

Either the level1 - level4 JDBC programs or ttIsql can be used to apply committed changes to the CUSTOMER, PRODUCT, ORDERS, ORDER_ITEM and INVENTORY tables
  Tptbm.java This program implements a multi-user throughput benchmark. By default, the transaction mix consists of 80% SELECT (read) transactions and 20% UPDATE (write) transactions. In addition to SELECTs and UPDATEs, INSERTs can also be included in the transaction mix. The ratio of SELECTs, UPDATEs and INSERTs is specified at the command line. Each transaction consists of one or more SQL operations.

The benchmark initially populates the data store, and then executes the transaction mix on it. The number of tuples inserted as part of the transaction mix cannot exceed the number of tuples with which the database is populated initially.

The measurement error for the benchmark is at most 2 seconds. This will be negligible at loads with a duration in excess of 200 seconds. A suggested load for the benchmark is one that lasts at least 600 seconds.

The schema for this test is described in the program source file tptbm.java.
 TTJdbcExamples.java  This program demonstrates the following operations using the TimesTen JDBC DriverManager interface to:
a) Connect and disconnect
b) Perform some DDL and DML operations: create table, create index, prepare statements, insert into and select from a table
c) Make changes to influence the query plan
d) Execute batch updates
  JDBC Connection Pool A sample JDBC connection pool implementation is available at the quickstart/sample_code/jdbc/connection_pool directory.

The above JDBC sample programs are available in the quickstart/sample_code/jdbc directory.

Compile and Run

Click here to learn how to compile and run the sample programs on your installed platform.

For more information on Java programming with Oracle TimesTen, refer to the Oracle TimesTen In-Memory Database Java Developer's Guide.