Oracle TimesTen
In-Memory Database
Java Developer’s and
Reference Guide
Release 7.0
B31681-01
Copyright ©1996, 2007, Oracle. All rights reserved.
ALL SOFTWARE AND DOCUMENTATION (WHETHER IN
HARD COPY OR ELECTRONIC FORM) ENCLOSED AND ON
THE COMPACT DISC(S) ARE SUBJECT TO THE LICENSE
AGREEMENT.
The documentation stored on the compact disc(s) may be printed by
licensee for licensee’s internal use only. Except for the foregoing,
no part of this documentation (whether in hard copy or electronic
form) may be reproduced or transmitted in any form by any means,
electronic or mechanical, including photocopying, recording, or
any information storage and retrieval system, without the prior
written permission of TimesTen Inc.
Oracle, JD Edwards, PeopleSoft, Retek, TimesTen, the TimesTen
icon, MicroLogging and Direct Data Access are trademarks or reg-
istered trademarks of Oracle Corporation and/or its affiliates. Other
names may be trademarks of their respective owners.
The Programs (which include both the software and documenta-
tion) contain proprietary information; they are provided under a li-
cense agreement containing restrictions on use and disclosure and
are also protected by copyright, patent, and other intellectual and
industrial property laws. Reverse engineering, disassembly, or de-
compilation of the Programs, except to the extent required to obtain
interoperability with other independently created software or as
specified by law, is prohibited.
The information contained in this document is subject to change
without notice. If you find any problems in the documentation,
please report them to us in writing. This document is not warranted
to be error-free. Except as may be expressly permitted in your li-
cense agreement for these Programs, no part of these Programs may
be reproduced or transmitted in any form or by any means, elec-
tronic or mechanical, for any purpose.
February 2007
Printed in the United States of America
iii
Contents
About this Guide
TimesTen documentation . . . . . . . . . . . . . . . . . . . . . 1
Background reading . . . . . . . . . . . . . . . . . . . . . . . 2
Conventions used in this guide . . . . . . . . . . . . . . . . . . . 3
Technical Support . . . . . . . . . . . . . . . . . . . . . . . . 5
1 Configuring the Java Development Environment
Installing TimesTen and the JDK . . . . . . . . . . . . . . . . . . 7
Setting the Java Environment Variables. . . . . . . . . . . . . . . . 8
Set CLASSPATH . . . . . . . . . . . . . . . . . . . . . . . 8
Set the shared library path variable . . . . . . . . . . . . . . . . 9
Set the THREADS_FLAG variable (UNIX only) . . . . . . . . . . 9
Set the PATH variable . . . . . . . . . . . . . . . . . . . . . 11
Compiling and Executing Java Applications . . . . . . . . . . . . . . 11
About the TimesTen Java Demos . . . . . . . . . . . . . . . . . . 12
About the TimesTen demo schema . . . . . . . . . . . . . . . . 12
What the TimesTen demos do . . . . . . . . . . . . . . . . . . 13
Compiling the TimesTen Java demos . . . . . . . . . . . . . . . 14
Executing the TimesTen Java demos . . . . . . . . . . . . . . . 15
Executing the level demos . . . . . . . . . . . . . . . . . . 15
Executing the XlaLevel demos . . . . . . . . . . . . . . . . 16
Problems executing the TimesTen Java demo programs . . . . . . 21
Problems compiling the TimesTen Java demo program . . . . . . 21
2 Working with TimesTen Data Stores
Java Classes . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Connecting to a TimesTen Data Store . . . . . . . . . . . . . . . . 24
Load the TimesTen driver. . . . . . . . . . . . . . . . . . . . 25
Create a connection URL for the data store . . . . . . . . . . . . . 25
Specifying data store attributes in the connection URL . . . . . . 26
Connect to the data store . . . . . . . . . . . . . . . . . . . . 26
Disconnect from the data store. . . . . . . . . . . . . . . . . . 26
Opening and closing a direct driver connection. . . . . . . . . . . . . 26
Managing TimesTen Data . . . . . . . . . . . . . . . . . . . . . 28
Calling SQL statements within Java applications . . . . . . . . . . 28
Setting autocommit . . . . . . . . . . . . . . . . . . . . 28
Preparing SQL statements . . . . . . . . . . . . . . . . . . 29
Executing SQL statements . . . . . . . . . . . . . . . . . . 31
Setting a timeout value for executing SQL statements . . . . . . . 33
iv Oracle TimesTen In-Memory Database Java Developer’s and Reference Guide
Putting it all together: preparing and executing SQL . . . . . . . .34
Fetching multiple rows of data . . . . . . . . . . . . . . . . . .35
Executing multiple SQL statements in a batch . . . . . . . . . . . .37
Working with result sets . . . . . . . . . . . . . . . . . . . .38
Calling TimesTen built-in procedures. . . . . . . . . . . . . . . . .39
Managing Multiple Threads . . . . . . . . . . . . . . . . . . . .41
Handling Errors . . . . . . . . . . . . . . . . . . . . . . . . .42
About fatal errors, non-fatal errors, and warnings . . . . . . . . . .42
Handling fatal errors and recovery . . . . . . . . . . . . . . .42
Handling non-fatal errors . . . . . . . . . . . . . . . . . .43
About warnings . . . . . . . . . . . . . . . . . . . . . .43
Reporting errors and warnings . . . . . . . . . . . . . . . . . .44
Detecting and responding to specific errors . . . . . . . . . . . . .46
Rolling back failed transactions . . . . . . . . . . . . . . . . .47
3 Using JMS/XLA for Event Management
JMS/XLA Concepts . . . . . . . . . . . . . . . . . . . . . . .50
How XLA reads records from the transaction log . . . . . . . . . .50
XLA and materialized views. . . . . . . . . . . . . . . . . . .52
XLA configuration file and topics . . . . . . . . . . . . . . . .52
XLA updates . . . . . . . . . . . . . . . . . . . . . . . . .53
XLA bookmarks . . . . . . . . . . . . . . . . . . . . . . .54
XLA acknowledgement modes. . . . . . . . . . . . . . . . . .55
Prefetching updates . . . . . . . . . . . . . . . . . . . .56
Acknowledging updates . . . . . . . . . . . . . . . . . . .56
XLA Demos . . . . . . . . . . . . . . . . . . . . . . . . . .56
XlaLevel1 demo . . . . . . . . . . . . . . . . . . . . . . .56
JMS/XLA and Oracle GDK dependency . . . . . . . . . . . . . . .56
Connecting to XLA. . . . . . . . . . . . . . . . . . . . . . . .57
Monitoring Tables for Updates . . . . . . . . . . . . . . . . . . .57
Receiving and Processing Updates. . . . . . . . . . . . . . . . . .58
Processing updates . . . . . . . . . . . . . . . . . . . . . .59
Terminating an XLA Application . . . . . . . . . . . . . . . . . .60
Closing the connection . . . . . . . . . . . . . . . . . . . . .61
Deleting bookmarks . . . . . . . . . . . . . . . . . . . . . .61
Unsubscribing from a table . . . . . . . . . . . . . . . . . . .61
Using XLA as a Replication Mechanism . . . . . . . . . . . . . . .62
TargetDataStore error recovery. . . . . . . . . . . . . . . . . .63
4 Application Tuning
Tuning Java applications. . . . . . . . . . . . . . . . . . . . . .65
Turn off autocommit mode . . . . . . . . . . . . . . . . . . .65
v
Choose a timeout interval . . . . . . . . . . . . . . . . . . . .66
Reduce contention. . . . . . . . . . . . . . . . . . . . . . .66
Choose the best method of locking . . . . . . . . . . . . . . . .67
Choose an appropriate lock level . . . . . . . . . . . . . . .67
Choose an appropriate isolation level . . . . . . . . . . . . . .67
Choose the appropriate logging options . . . . . . . . . . . . . .68
Prepare statements in advance . . . . . . . . . . . . . . . . . .69
Avoid unnecessary prepare operations . . . . . . . . . . . . . . .69
Use the batch update facility for executing multiple statements . . . . .70
Bulk fetch rows of TimesTen data. . . . . . . . . . . . . . . . .71
Size transactions appropriately . . . . . . . . . . . . . . . . . .71
Use durable commits appropriately . . . . . . . . . . . . . . . .72
Use the ResultSet.getString method sparingly . . . . . . . . . . . .72
Avoid data type conversions . . . . . . . . . . . . . . . . . . .73
Avoid transaction rollback . . . . . . . . . . . . . . . . . . .73
Avoid frequent checkpoints . . . . . . . . . . . . . . . . . . .73
Tuning JMS/XLA applications . . . . . . . . . . . . . . . . . . .74
Configure xlaPrefetch parameter . . . . . . . . . . . . . . . . .74
Batch calls to ttXlaAcknowledge . . . . . . . . . . . . . . . . .74
Increase log buffer size . . . . . . . . . . . . . . . . . . . . .74
Handling high event rates . . . . . . . . . . . . . . . . . . . .74
5 JDBC Reference
Supported JDBC Interfaces. . . . . . . . . . . . . . . . . . . . .77
Support for interfaces in java.sql package . . . . . . . . . . . . .77
CallableStatement . . . . . . . . . . . . . . . . . . . . .78
Connection . . . . . . . . . . . . . . . . . . . . . . . .78
DatabaseMetaData . . . . . . . . . . . . . . . . . . . . .78
Driver . . . . . . . . . . . . . . . . . . . . . . . . . .78
ParameterMetaData . . . . . . . . . . . . . . . . . . . .79
PreparedStatement . . . . . . . . . . . . . . . . . . . . .79
ResultSet . . . . . . . . . . . . . . . . . . . . . . . . .79
ResultSetMetaData . . . . . . . . . . . . . . . . . . . . .79
Statement . . . . . . . . . . . . . . . . . . . . . . . .79
Support for interfaces in javax.sql package . . . . . . . . . . . . .80
DataSource . . . . . . . . . . . . . . . . . . . . . . . .80
ConnectionPoolDataSource . . . . . . . . . . . . . . . . .80
PooledConnection . . . . . . . . . . . . . . . . . . . . .80
XADataSource . . . . . . . . . . . . . . . . . . . . . .80
TimesTen Extensions to JDBC . . . . . . . . . . . . . . . . . . .80
TimesTenConnection. . . . . . . . . . . . . . . . . . . . . .80
getTtPrefetchClose . . . . . . . . . . . . . . . . . . . . .81
getTtPrefetchCount . . . . . . . . . . . . . . . . . . . . .81
评论0