Rocket JDBC Connection
Rocket JDBC Connection
fm
March 8, 2010 1:38 pm
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Beta Beta Beta Beta
UDT-720-JDBC-1
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCTITL.fm
March 8, 2010 1:38 pm
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Notices
Edition
Publication date: June 2008
Book number: UDT-720-JDBC-1
Product version: UniData 7.2
Copyright
© Rocket Software, Inc. 1988-2008. All Rights Reserved.
Trademarks
The following trademarks appear in this publication:
Java™ and all Java-based trademarks and logos Sun Microsystems, Inc.
License agreement
This software and the associated documentation are proprietary and confidential to
Rocket Software, Inc., are furnished under license, and may be used and copied only
in accordance with the terms of such license and with the inclusion of the copyright
notice. This software and any copies thereof may not be provided or otherwise made
available to any other person. No title to or ownership of the software and associated
documentation is hereby transferred. Any unauthorized use or reproduction of this
software or documentation may be subject to civil or criminal liability. The information
in the software and documentation is subject to change and should not be construed
as a commitment by Rocket Software, Inc.
Restricted rights notice for license to the U.S. Government: Use, reproduction, or
disclosure is subject to restrictions as stated in the “Rights in Technical Data-
General” clause (alternate III), in FAR section 52.222-14. All title and ownership in
this computer software remain with Rocket Software, Inc.
Note
This product may contain encryption technology. Many countries prohibit or restrict
the use, import, or export of encryption technologies, and current use, import, and
export regulations should be followed when exporting this product.
Please be aware: Any images or indications reflecting ownership or branding of the
product(s) documented herein may or may not reflect the current legal ownership of
the intellectual property rights associated with such product(s). All right and title to
the product(s) documented herein belong solely to Rocket Software, Inc. and its
subsidiaries, notwithstanding any notices (including screen captures) or any other
indications to the contrary.
Contact information
Rocket Software
275 Grove Street Suite 3-410
Newton, MA 02466-2272
USA
Tel: (617) 614-4321 Fax: (617) 630-7100
Web Site: www.rocketsoftware.com
Using the IBM JDBC Driver for UniData and UniVerse iii
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Table of
Contents
Table of Contents
Chapter 2 Installing and Setting Up the IBM JDBC Driver for UniData
and UniVerse
Hardware and Software Requirements . . . . . . . . . . . . 2-3
Installing the IBM JDBC Driver for UniData and UniVerse . . . . . . 2-5
Installing on Windows Platforms. . . . . . . . . . . . . 2-5
Installing on UNIX . . . . . . . . . . . . . . . . . 2-6
Table of Contents v
Chapter 7 IBM for UniData and UniVerse JDBC Code Examples
UniJDBC Example Program - List File . . . . . . . . . . . . 7-3
UniJDBC Short Examples . . . . . . . . . . . . . . . . 7-7
Select Example . . . . . . . . . . . . . . . . . . 7-7
UniJDBC Prepared Statement Example . . . . . . . . . . 7-9
UniJDBC Callable Statement Example . . . . . . . . . . 7-10
UniJDBC DatabaseMetaData Example . . . . . . . . . . 7-11
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
This manual provides an overview of JDBC technology and how the IBM JDBC
Driver for UniData and UniVerse uses it to expose UniData and UniVerse extended
relational data. This manual also describes how to configure the IBM JDBC Driver
for UniData and UniVerse, and provides information about the JDBC functionality
that it supports. From this information, developers can design JDBC-based applica-
tions that can access and manipulate data in UniData and UniVerse data stores.
The IBM JDBC Driver for UniData and UniVerse is an implementation of the JDBC
1.0 specification with limited functionality supported for the JDBC 2.0 specification.
1-2 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
1-3
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH01.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
What is JDBC
Java database connectivity (JDBC) is the JavaSoft specification of a standard appli-
cation programming interface (API) that allows Java programs to access database
management systems. The JDBC API consists of a set of interfaces and classes
written in the Java programming language.
Using these standard interfaces and classes, programmers can write applications that
connect to databases, send queries written in structured query language (SQL), and
process the results.
The JDBC API is consistent with the style of the core Java interfaces and classes,
such as java.lang and java.awt. The following table describes the interfaces, classes,
and exceptions that make up the JDBC API.
1-4 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Since JDBC is a standard specification, one Java program that uses the JDBC API
can connect to any database management system (DBMS), as long as a driver exists
for that particular DBMS.
For more information about the JDBC API, visit the JavaSoft Web Site at:
http://java.sun.com/
1-5
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH01.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
The JDBC API consists of a set of classes and interfaces written in the Java
programming language that provide a standard API for database developers, and
makes it possible to write robust database applications using an all-Java API. A
JDBC driver implements these interfaces and classes for a particular DBMS vendor.
A Java program that uses the JDBC API loads the specified driver for a particular
DBMS before it actually connects to a database. The JDBC Driver-Manager class
then sends all JDBC API calls to the loaded driver.
1. JDBC-ODBC bridge plus ODBC driver (also called Type 1): This type of
driver translates JDBC API calls into ODBC calls that are then passed to the
ODBC driver. ODBC binary code, and in many cases database client code,
must be loaded on each client machine that uses this driver. As a result, this
kind of driver is most appropriate on a corporate network where client
installations are easily managed, or for application server code written in
Java in a three tier architecture.
2. Native-API, partly java driver (also called Type 2): This kind of driver
converts JDBC API calls into DBMS-specific client API calls. Like the
bridge driver, this type of driver requires that some binary code be loaded
on each client computer.
3. JDBC-Net, pure-Java driver (also called Type 3): This driver translates
JDBC calls into a DBMS-independent net protocol, which is then translated
to a DBMS protocol by a server.
4. Native-Protocol, pure-Java driver (also called Type 4): This type of driver
converts JDBC API calls directly into the DBMS-specific network protocol
without a middle tier. This allows the client applications to connect directly
to the database server.
The IBM JDBC Driver for UniData and UniVerse is a Type 4, Native-Protocol,
driver.
1-6 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Overview of JDBC
The IBM JDBC Driver for UniData and UniVerse enables JDBC applications to connect
to the UniData and UniVerse Relational Database Management Systems (RDBMS).
The IBM JDBC Driver for UniData and UniVerse is a Type 4 or Native Protocol type
driver and is an implementation of the JDBC 1.0 specification with support for some 2.0
functionality.
A JDBC application sends a connection request to the IBM JDBC Driver for UniData
and UniVerse. The driver receives the request, and establishes a connection to the
UniData or UniVerse RDBMS. Then the JDBC application can access the RDBMS.
When the process is complete, the JDBC application sends a disconnection request to
the IBM JDBC Driver for UniData and UniVerse, and disconnects from the RDBMS.
In order to access the data from a JDBC application, the data must conform to the 1NF
standard, or be “normalized.”
UniVerse dynamically normalizes its own data. For more information, see Chapter 4,
“Accessing UniVerse Data.”
UniData also normalizes its own data, but you must prepare the data for it to do so. To
prepare the data, you must use VSG, a GUI tool that generates schema on UniData files,
or the Schema API. For more information about using VSG or the Schema API, see
Chapter 3, “Accessing UniData Data,” and Using VSG and the Schema API.
1-7
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH01.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
JDBC Application
IBM JDBC
J Driver
UniRPC
UniData UniVerse
DBMS
RDBMS DBMS
RDBMS
1-8 Using the IBM JDBC Driver for UniData and UniVerse
0
Chapter
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
This chapter describes how to prepare both a client and server machine to run IBM
JDBC for UniData and UniVerse.
2-2 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Client Requirements
Windows Client
IBM-compatible personal computer (PC) attached to a network.
Either of the following operating systems:
Windows platforms NT 4.0 (Service Pack #6) or later (for example,
Windows 2000, Windows XP, and so forth)
Approximately 20 MB of free disk space.
A minimum of 64 MB of random access memory (RAM).
TCP/IP.
Java 1.2 or greater must be installed.
If you wish to use any of the extended options from the JDBC 2.0 Optional
API, such as connecting through a data source or the use of connection
pooling, you must obtain an implementation of the Java Directory and
Naming Interface (JNDI). You need to download and install the JDBC
Optional Package from Javasoft, which includes a required import package
(javax.sql.*) for any JDBC application making use of the Optional API.
Also required are the JNDI 1.2.1 class libraries (javax.naming.*), which you
can download if you are not using JDK 1.3 or higher. If you are using JDK
1.3 or higher, the JNDI libraries are included.
UNIX Client
Java 1.2 or greater must be installed
Server Requirements
UNIX, Windows NT or higher (for example, Windows 2000, Windows XP,
and so forth).
TCP/IP.
2-3
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH02.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
2-4 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
2-5
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH02.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Installing on UNIX
The following section describes how to install JDBC on UNIX systems.
This command tells you the path to the unishared directory. The JDBC files located
in this directory have the following structure:
/unishared
/jdbc/docs/unijdbcjavadoc.zip
/jdbc/lib/unijdbc.jar
/jdbc/samples/jdbcsample.zip
/uojskd/lib/asjava.zip
Another required file, asjava.zip is located in the UniObjects for Java installation in
the path shown above. The files and their functions are as follows:
unijdbc.jar - The main driver file for the IBM Driver for UniData and
UniVerse.
asjava.zip - Contains required libraries for UniJDBC and UniObjects for
Java
unijdbcjavadoc.zip - The javadoc for the UniJDBC driver code.
jdbcsample.zip - A sample UniJDBC program for reference.
Set your classpath environment variable to include unijdbc.jar and asjava.zip. For
example, enter the following command when using ksh:
export
CLASSPATH=/unishared/jdbc/lib/unijdbc.jar:/unishared/uojsdk/lib/as
java.zip:$CLASSPATH
2-6 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
After you copy the files to your UNIX client machine, you must set your classpath.
See the “Installing the IBM JDBC Driver for UniData and UniVerse” on page 2-5 for
further details about setting the classpath.
Once you copy the files and set the classpath, you are ready to get started.
2-7
Chapter
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
This chapter describes how to access data in UniData tables and files. You must
perform the following tasks:
Verify that the UniRPC daemon (for UNIX systems) or the UniRPC service
(for Windows platforms) is running.
Make UniData accounts accessible to JDBC applications.
Present the data in UniData in a format that is accessible to JDBC
applications.
3-2
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH03.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
On UNIX systems, you can verify whether UniRPC is running by entering the
following command:
If you need to start UniRPC for UNIX, use the UniData startud command. For more
information, see Administrative Supplement for APIs included with both the UniData
and UniVerse documentation sets.
On UNIX systems, the UniRPC services file (unirpcservices) contains an entry that
is similar to the following example:
On Windows platforms, the unirpcservices file is located on the UCI server in the
following default path:
x:\IBM\unishared\unirpc
where x is the drive on which the software is installed. It contains an entry that is
similar to the following example:
3-3 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Your unishared directory might not be located in the default path. To determine its
actual location on UNIX systems, enter:
cat /.unishared
For Windows platforms, you can find the path for unishared by looking in the system
registry in \HKEY_LOCAL_MACHINE\SOFTWARE\IBM\unishared.
When the client system requests a connection to a UCI server, the local UniRPC
daemon or service uses the unirpcservices file to verify that the client can start the
requested server (in this case, udserver).
With the Server edition of UniData, each JDBC connection to a UniData UCI server
consumes one UniData license. With the Workstation, Workgroup, or Enterprise
edition of UniData, device licensing enables each client system to establish up to ten
connections to the UCI server from one device while consuming only one database
license — regardless of whether more than one user login is used to make the connec-
tions. For more information about device licensing, see Installing and Licensing
UniData Products and the Administrative Supplement for APIs.
Note: To edit the unirpcservices file, you must have root privileges on UNIX or
Administrator privileges on Windows platforms.
For example, to set the connection timeout delay to 24 hours, in the line starting with
udserver, change the right-most number to 864000 (the number of “seconds” in 24
hours). The line could appear as follows:
3-4
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH03.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
You can specify the account under the account property of the connection URL.
If you want to access an account that has a UDTHOME directory different than the
default UDTHOME directory, you must include a definition for that account in the
ud_database file on the server machine. For UNIX systems, this file is located in the
/usr/udnn/include path, where nn is the release of UniData you are running. For
Windows platforms, it is located in \udthome\include. You can find the path for
udthome by looking in the system registry under
\HKEY_LOCAL_MACHINE\SOFTWARE\IBM\UniData\7.2. Use any text editor
to modify the ud_database file.
Note: To determine your default UniData home directory, use the UNIX env
command. The results of this command include the default setting for the UDTHOME
environment variable.
The following Windows example shows an entry in the ud_database file for a
database named db2:
DATABASE=db2
UDTHOME=d:\disk2\test72
UDTACCT=d:\disk2\test72\testacct.
In the ud_database file entry, the UDTHOME parameter is optional. You should
include it only when the UDTHOME directory is different than the default
UDTHOME directory.
Tracing Events
By using the tracing feature, you can create logs of events between clients and the
database through the server. Logs enable IBM support personnel to help troubleshoot
problems. You can define trace levels for database entries in the ud_database file.
3-5 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
The following table describes the valid trace levels and the associated information
that is written to the trace log.
The following UNIX example shows a tracing level setting for a database named
dbase3:
DATABASE=dbase3
UDTHOME=/disk1/ud71
UDTACCT=/home/username/test
TRACE_LEVEL=3
3-6
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH03.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Data types
Multivalued and multi-subvalued data
Data Types
UniData does not define data types for data contained in its files. On the other hand,
JDBC expects data types for all data. In addition, data in UniData can be of variable
length, but JDBC expects data to have either a fixed or a maximum length. To make
the data look more like what JDBC expects, you must use VSG or the Schema API.
VSG or the Schema API create views and subtables that present multivalued and
multi-subvalued data in 1NF format. These views and subtables do not duplicate
data, but merely instruct UniData SQL to normalize data before returning it to the
application. JDBC passes the 1NF data to the Java application in the form of rowsets.
VSG
Schema API
3-7 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
VSG is a Windows-based graphical user interface (GUI) tool that makes UniData
files accessible to other applications through JDBC. It enables you to create, delete,
and modify UniData SQL subtables and views. VSG also enables you to set ANSI
privileges (security) for tables, subtables, and views.
VSG guides data administrators through the process of defining the 1NF subtables
and views that represent the extended relations by visually presenting all available
configuration options. It also translates conversion specifications for UniData to SQL
data types. VSG performs logical error checking through every step of the schema
generation process.
IBM recommends that you use VSG to prepare files because it is easier and faster to
use than the Schema API. It performs several processes automatically. You might
want to use the Schema API if you have a large number of files (in this case, several
VSG processes take several minutes to complete) or you deploy data files with your
applications.
For more information about using VSG or the Schema API, see Using VSG and the
Schema API.
3-8
Chapter
This chapter describes how to access data in UniVerse tables and files. The following
data is always accessible to a JDBC application connected to a UniVerse account:
In this chapter, the word tables refers to UniVerse tables defined by the CREATE
TABLE statement, and views defined by the CREATE VIEW statement. The word
files refers to non-SQL UniVerse files that are created by the CREATE.FILE
command. The term JDBC table refers to any table or file, real or virtual, that is
accessible to JDBC applications.
For information about setting up data sources, see Chapter 2, “Installing and Setting
Up the IBM JDBC Driver for UniData and UniVerse.”
4-2
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
We refer to the JDBC tables listed in the TABLES rowset as “visible” to JDBC appli-
cations. Although all SQL tables on the system are, by definition, visible, non-SQL
files that have not been made visible are not included in the TABLES rowset. For
information about how to make files visible in an account, see “Making Files Visible
to JDBC Applications” on page 4-12.
Tables
When connected to a UniVerse account, a JDBC application can access all tables on
the system. If connected to a UniVerse schema, the JDBC application can reference
tables in that schema by using unqualified table names in SQL statements. All other
tables on the system can be referenced using table names qualified by the appropriate
schema name.
Example 1
In this example the JDBC application is connected to schema HR. If table
EMPLOYEES is in schema HR, you can reference it simply as EMPLOYEES. If
view EMPLOYEES is in schema DENVER, you must reference it as
DENVER.EMPLOYEES.
4-3 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Example 2
In this example, the JDBC application is connected to account SALES that is not a
schema. In this case, you must reference table EMPLOYEES (in schema HR) and
view EMPLOYEES (in schema DENVER) as HR.EMPLOYEES and
DENVER.EMPLOYEES respectively.
Files
A JDBC application can access files that are defined in the VOC file of the account
to which the JDBC application is connected. Because some JDBC applications are
written to access only tables listed in the TABLES rowset, as a practical matter
UniVerse files may not be usable unless they have been made visible for that account.
For example, if a JDBC application connects to an account whose files have been
made visible, all files defined in the account’s VOC file, except for system files (such
as &SAVEDLISTS&) and UV/Net files, are visible. The JDBC application can
reference the files using the file names in the VOC. The account does not need to be
a schema.
On the other hand, if a JDBC application connects to an account whose files have not
been made visible, no files appear in the TABLES rowset. However, the JDBC appli-
cation can still access files defined in the account’s VOC file.
Multivalued Data
JDBC applications expect data to be organized relationally in first normal form
(1NF). Although some UniVerse tables and files are in first normal form, which
means only one value is stored in each column of each row, many UniVerse tables
and files have columns that store multiple values.
UniVerse always presents multivalued data to JDBC in first normal form (1NF), and
JDBC passes it to the java applications in the form of rowsets. UniVerse automati-
cally normalizes its tables and files by a process called “dynamic normalization.”
This means that a file containing multivalued data appears to JDBC as several 1NF
tables, each consisting of singlevalued data only.
4-4
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Example
The table ORDERS is defined with columns ORDERNUM, CUSTNUM, DATE,
PART, and QTY. PART and QTY are multivalued and make up an association called
ITEMS. The association key is PART. Suppose this table contains the following
orders.
BOLT 650
This file appears to JDBC as two 1NF tables called ORDERS and ORDERS_ITEMS.
The ORDERNUM column is the ORDERS key.
The ORDERNUM and PART columns are the two columns that make up the
ORDERS_ITEMS key.
99102 BOLT 50
ORDERS 1NF Table
4-5 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Example 1
Suppose the JDBC application is connected to a UniVerse account that is not a
schema, and suppose the account contains two files called EMPS and DEPTS. EMPS
and DEPTS are not tables. EMPS has one multivalued column called DEPEN-
DENTS, and DEPTS has no multivalued columns. Files in this account have been
made visible.
Suppose there is another UniVerse account whose files have been made visible,
which contains a file called OTHERFILE.
If the JDBC application requests the TABLES rowset, it includes the following
information.
Any files listed in the TABLES rowset must be in the account to which the
JDBC application is connected (OTHERFILE does not appear).
Files listed in the TABLES rowset have a null value for the schema name.
A multivalued column appears as a separate dynamically-normalized table
whose type is TABLE and whose name is composed of the original file’s
name followed by an underscore and the name of the column.
Example 2
Suppose the above account is made into a schema named USA. Suppose two tables
called CITIES and STATES are then created where CITIES has only single-valued
columns and STATES has an association called COUNTIES.
4-6
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Example 3
Suppose an SQL view called STATEVIEW is created in another schema (called
JOESCHEMA) with the following SQL statement:
CREATE VIEW STATEVIEW AS SELECT * FROM USA.STATES;
While still connected to the original account, the JDBC application sees the following
information returned in the TABLES rowset.
4-7 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Example 4
Suppose the account JOESCHEMA mentioned above contains a UniVerse file called
JOEFILE that has not been made visible. Suppose a JDBC application connects to
JOESCHEMA and requests the TABLES rowset. This rowset includes the following
information.
This shows:
4-8
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Example 5
The UniVerse SQL catalog tables also appear in the TABLES rowset. Their table type
is SYSTEM TABLE.
4-9 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
4-10
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
1. List activated accounts Lists UniVerse accounts whose files have been made
visible to JDBC. When a JDBC application is
connected to such an account, the account’s files are
included in the TABLES rowset.
5. Run HS.SCRUB on a File/Table Analyzes the data in a table or file, and lets you
optionally correct anomalous data.
6. Update File Information Cache Updates this account’s .hs_fileinfo file to reflect the
in an account current state of all files in the account.
UniVerse Server Administration Menu Selections
4-11 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Scans the dictionaries of all non-system files named in the VOC, finding all
associations and unassociated multivalued columns.
Writes an @EMPTY.NULL X-record in each file dictionary.
Writes S or M in field 5 of A- and S-descriptors.
Creates Q-pointers in the VOC for files comprising multiple data files.
Creates an HS_FILE_A000HS_FILE_A000 file in the account.
Creates a file information cache (.hs_fileinfo) under the account’s directory,
which contains a compressed list of all 1NF file names in the account and is
used by the JDBC Driver to rapidly construct the TABLES rowset whenever
a Java application requests it to do so.
Updates the UV.ACCOUNT file to indicate that the files in the account have
been made visible.
4-12
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
HS_DEFAULT READ_WRITE
&DEVICE& NONE
. .
. .
. .
VOC NONE
VOCLIB NONE
Initial Contents of HS_FILE_A000
You can edit the HS_FILE_A000 file to control which files in the account are visible
to JDBC applications.
The IDs of records in the HS_FILE_A000 file are the names of the files whose access
you want to control. Each record has one field (ACCESS), which contains one of the
following values:
READ_WRITE
READ
NONE
If the ACCESS field for a file is set to READ, this is treated the same as
READ_WRITE for JDBC.
The HS_FILE_A000 file contains a special record called HS_DEFAULT which con-
trols default access to all files in the account. When you first make files visible, the
HS_DEFAULT record is set to READ_WRITE and the records for UniVerse system
files (APP.PROGS, BASIC.HELP, ERRMSG, UV.ACCOUNT, DICT.DICT,
NEWACC, and so forth) are set to NONE (no access).
To remove visibility from a few selected files and leave the rest visible to JDBC, add
a record to HS_FILE_A000 for each restricted file, with the ACCESS field set to
NONE.
4-13 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
To make just a few files in an account visible to JDBC, change the ACCESS field in
the HS_DEFAULT record from READ_WRITE to NONE, and then add selected
files whose ACCESS field is READ_WRITE.
If you change the contents of the HS_FILE_A000 file, you must then update the file
information cache for your changes to take effect. For information about updating the
file information cache, see the next section.
These types of change are not reflected in the TABLES rowset until the account’s file
information cache is updated.
You can update the file information cache using the UniVerse Server Administration
menu or the HS.UPDATE.FILEINFO command.
Complete the following steps to update the file information cache using the menu:
4-14
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Warning: The file information cache is for internal use only and should not be
modified. Any changes to the cache can cause unpredictable behavior and can make
UniVerse files in the account inaccessible to JDBC applications.
Example
Suppose account MYACCOUNT contains the following files:
After the files in this account are made visible, the TABLES rowset lists the
following tables.
4-15 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
These changes are not immediately reflected in the TABLES rowset, but after
MYACCOUNT’s file information cache is updated, the TABLES rowset lists the
following information.
4-16
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
4-17 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Columns other than those returned in the COLUMNS rowset may be accessible by
JDBC applications, since "SELECT *" does not always return all columns defined in
the dictionary.
COLUMNS Rowset
A JDBC application can request a COLUMNS rowset, which provides a list of
column characteristics. Each row in the COLUMNS rowset includes the following
information:
Schema name
Table name
Column name
Column position
Data type
Precision
Scale
For UniVerse tables, and all multivalued columns within them, columns listed in the
COLUMNS rowset are defined by the dictionary’s @SELECT phrase (if it exists), or
are defined as the columns created by CREATE TABLE (and possibly modified by
ALTER TABLE) if there is no @SELECT phrase.
4-18
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
For files, and for associations and unassociated multivalued columns within them,
columns listed in the COLUMNS rowset are defined by the dictionary’s @SELECT
phrase (if it exists). If there is no @SELECT phrase, the contents of the COLUMNS
rowset are defined by the dictionary’s @ phrase (if it exists). If neither an @SELECT
phrase nor an @ phrase exists, only the record ID (@ID) appears in the COLUMNS
rowset.
For more information about the @SELECT and @ phrases, see UniVerse Adminis-
tration for DBAs.
Association Keys
UniVerse tables have primary keys. UniVerse files have record IDs. Primary keys and
record IDs are unique identifiers for each row (record) of data in a table or file.
When you create a UniVerse table or file, you can define one or more association
columns as the association key, but you do not have to. If you do not, UniVerse SQL
generates a virtual column called @ASSOC_ROW containing unique values that,
combined with the primary keys or record IDs of the base table, become the associ-
ation keys for the 1NF table generated from the association.
For detailed information about defining association keys, see UniVerse SQL Admin-
istration for DBAs and the UniVerse SQL Reference.
Example
The file EMPS is defined with columns EMPNUM, NAME, DEPTNUM, DEPEN-
DENTS, and PHONES, where DEPENDENTS and PHONES are unassociated
multivalued columns. Suppose this file contains the following employees.
FREDERICA
4-19 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
555-245-1456
ALFRED 400-765-9010
SAMUEL
EMPS File
This table will appear to JDBC as three 1NF tables called EMPS,
EMPS_DEPENDENTS, and EMPS_PHONES.
4456 GONZALES 97
4901 HURLBUT 58
6511 RICHARDS 58
EMPS NF1 Table
4456 SUSAN 1
4456 FREDERICA 2
6511 HELEN 1
6511 ALFRED 2
6511 SAMUEL 3
EMPS_DEPENDENTS 1NF Table
4-20
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
The EMPS_PHONES 1NF table also has a two-column key consisting of EMPNUM
and @ASSOC_ROW.
4456 555-876-4041 1
4901 555-245-1000 1
4901 555-245-1456 2
6511 400-765-4321 1
6511 400-765-9010 2
EMPS_PHONES 1NF Table
4-21 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Delimited Identifiers
UniVerse supports an ANSI-SQL feature called "delimited identifiers." This means
that any identifier (table name, column name, index name, constraint name, and so
forth) can be enclosed in double quotation marks to avoid ambiguity in the syntax of
an SQL statement. This is particularly useful in the case of UniVerse table and
column names that contain the period (.) character.
The following example shows a SELECT statement that contains column and table
names delimited by double-quotation marks:
SELECT "MY.COLUMN" FROM SCHEMAX."MY.TABLE";
4-22
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
4-23 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
If the DATATYPE field is empty, UniVerse determines a column’s SQL data type by
examining its conversion code and format specifications. The UniVerse server
reports this SQL data type to JDBC applications in the COLUMNS rowset. If the
UniVerse-generated SQL data type is inappropriate for the actual data in the column,
you can specify the correct SQL data type in the DATATYPE field of the column’s
dictionary entry. For some data types, the SQL data type syntax is different between
dictionary specifications and UniVerse SQL statements (for example, CREATE
TABLE) as noted in the following table. Square brackets indicate optional
parameters.
Note the syntactic differences regarding the use of parentheses and commas.
The DATE, DOUBLE PRECISION, INT [ EGER ], REAL, SMALLINT, and TIME
data type syntax is identical for dictionaries and UniVerse SQL.
You can specify the SQL data type for any column, real or virtual, in a UniVerse file.
You need not specify the SQL data type for any column of a table defined by the
CREATE TABLE or CREATE VIEW statement, but you may want to specify the
SQL data type for other columns in the table (such as I-descriptors) that are not
defined in the SICA. You cannot modify the SQL data type for columns defined in
the SICA, and UniVerse ignores the dictionary definitions for these columns. For
more information about the SICA and UniVerse tables, see UniVerse SQL Adminis-
tration for DBAs manual and the UniVerse SQL User Guide.
4-24
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
For a column in a UniVerse file, the precision is defined by the data type
specified in the DATATYPE field of the column’s dictionary definition. If
the data type is not defined, the FORMAT field of the dictionary defines the
precision.
For a column defined by a CREATE TABLE or ALTER TABLE statement,
the precision is defined by the column definition, which is stored in the
table’s SICA.
For a column in a view, the precision is defined by the CREATE VIEW
statement or by the precision of the column specified by the SELECT
statement that creates the view.
For a column added to a table’s dictionary (such as an I-descriptor), the
precision is defined by the data type specified in the DATATYPE field of the
column’s dictionary definition. If the data type is not defined, the FORMAT
field of the dictionary defines the precision.
You can use the HS.SCRUB utility to examine a file’s data and write appropriate data
types in the DATATYPE field of the dictionary definitions for character-string
columns. For information about HS.SCRUB, see “Validating and Fixing Tables and
Files” on page 4-26.
The actual number of characters in a UniVerse character column can be greater than
its precision. JDBC retrieves such extra characters, up to a limit. The number of bytes
of character data that JDBC retrieves from a character column is the smallest of:
If your fetch buffer is not large enough to hold all the character data that the JDBC
application retrieves, it generates a truncation warning.
The actual number of characters in a UniVerse character column can be less than its
precision. Unlike some DBMSs, UniVerse does not automatically pad CHAR(n)
columns on the right with spaces. If you insert the value "abc " (with two trailing
spaces) into a CHAR(10) column, the column contains only five characters, not 10.
Your application and data source must agree on a consistent way to treat trailing
spaces in a CHAR(n) column. Generally, it is better to treat CHAR(n) columns as if
they were VARCHAR columns with no space padding.
4-25 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Empty-Null Mapping
UniVerse files use empty strings in much the same way tables use null values. Unfor-
tunately, empty strings in numeric or date columns cause data conversion errors in
JDBC, making these columns almost inaccessible to some JDBC applications. To
make files with empty values accessible to JDBC applications, the UniVerse server
provides empty-null mapping, converting empty values in UniVerse files to null
values in JDBC application buffers, and vice versa.
The third selection (Activate access to files in an account) on the UniVerse Server
Administration menu enables empty-null mapping in all files in the account by
creating @EMPTY.NULL dictionary entries.
4-26
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
For information about @SELECT records, see UniVerse SQL Administration for
DBAs.
If you use the HS.SCRUB utility on a File/Table selection, the system prompts you
to enter either the full path of the UniVerse account (for Windows platforms, start
with the drive letter, such as D:) or the account name as listed in the UV.ACCOUNT
file. Press ENTER to see a list of UniVerse accounts whose files have been made
visible to JDBC.
Next the system prompts you to enter the name of the table or file you want to analyze
or change. After you enter a file name, the system prompts you to enter the mode of
operation. Enter one of the following at the Mode prompt:
4-27 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
AUTOFIX DATA
Parameter Description
FIX Puts HS.SCRUB in interactive mode, in which the system prompts you to
resolve any anomalies following the analysis.
AUTOFIX Puts HS.SCRUB in automatic mode; anomalies are corrected with the
default action that would have been presented to the user. If you do not
specify DICT or DATA with the AUTOFIX option, HS.SCRUB resolves
anomalies in both the data file or table and its dictionary.
DICT Indicates that HS.SCRUB resolves only those anomalies associated with
the file’s or table’s dictionary.
DATA Indicates that HS.SCRUB resolves only those anomalies associated with
the file’s or table’s data.
HS.SCRUB Parameters
When neither FIX nor AUTOFIX is specified, HS.SCRUB only reports anomalies.
No data or dictionary items are modified.
4-28
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Scalar Functions
The following table lists UniVerse JDBC support of scalar functions.
Function Supported
String ASCII No
CHAR No
CONCAT Yes
DIFFERENCE No
INSERTa Yes
LCASE Yes
LEFT Yes
LENGTH Yes
LOCATE No
LTRIM Yes
REPEAT No
REPLACE No
RIGHT1 Yes
RTRIM Yes
SOUNDEX No
SPACE No
SUBSTRING Yes
UCASE Yes
Numeric ABS No
ACOS No
UniVerse JDBC Support of Scalar Functions
4-29 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Function Supported
ASIN No
ATAN No
ATAN2 No
CEILING No
COS No
COT No
DEGREES Yes
EXP No
FLOOR No
LOG No
LOG10 No
MOD No
PI Yes
POWER No
RADIANS Yes
RAND No
ROUND No
SIGN No
SIN No
SQRT No
TAN No
TRUNCATE No
CURTIME No
UniVerse JDBC Support of Scalar Functions (Continued)
4-30
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH04.fm
3/8/10
Function Supported
DAYNAME No
DAYOFMONTH No
DAYOFWEEK No
DAYOFYEAR No
HOUR No
MINUTE No
MONTH No
MONTHNAME No
NOW No
QUARTER No
SECOND No
TIMESTAMPADD No
TIMESTAMPDIFF No
WEEK No
YEAR No
IFNULL No
USER Yes
4-31 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
a. INSERT and RIGHT may evaluate their arguments more than once,
consequently you cannot use a parameter marker as an argument to
these functions, and you must watch out for side effects if you use an I-
descriptor.
b. UniVerse JDBC supports the same conversions that UniVerse SQL
CAST supports.
4-32
Chapter
This chapter explains the IBM-specific information you need to use the IBM JDBC
Driver for UniData and UniVerse to connect to your database.
5-2
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
The Class.forName() method loads the IBM implementation of the Driver class,
UniJDBCDriver. The UniJDBCDriver class then creates an instance of the driver and
registers it with the DriverManager class.
Once you load the IBM JDBC Driver for UniData and UniVerse, you are ready to
connect to the database.
5-3 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Creating a Connection
To create a connection to a UniData or UniVerse database, use the
DriverManager.getConnection() method. This method creates a Connection object,
which is later used to create and send SQL statements to the database, and then
process the results.
The DriverManager class keeps track of the available drivers and handles connection
requests between appropriate drivers and databases. The url parameter of the getCon-
nection() method is a database URL that specifies the host name, port number and
account path. These are the required properties defined in the table below. An
optional second parameter to the getConnection() method, property, is the property
list defined in the following table.
The required properties for the connection string are listed in the following table.
Database
URL
Variable Description
port The port number of the UniRPC server running on the host. The
default port number is 31438.
5-4
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
The optional connection properties for the connection string are listed in the
following table.
Database URL
Variable Description
dbmstype The database type to which you will be connecting. Must be UniData or
UniVerse. The default setting is UniVerse.
network Specifies the network used to access the sql server. The default value is
TCP/IP.
proxyhost The host name for the proxy server being used.
proxyport The port number of the proxy server. The default value is 31448.
The following example shows a database URL that connects to the UniData demo
account, demo:
try {
Class.forName("com.ibm.u2.jdbc.UniJDBCDriver");
String sUrl = "jdbc:ibm-
u2://localhost/d:/ibm/ud60/demo;dbmstype=UNIDATA";
Connection con = DriverManager.getConnection(sUrl,"user",
"pass");
}
catch (Exception e) {
5-5 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
5-6
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
In UniVerse, the getSchemas() method returns the schema names available in the
database information and which accounts are accessible by JDBC. In UniData, the
getSchemas() method returns the owner of every table in the account to which you
are connected.
The getTables() method contains SQL tables and database files which are accessible
by JDBC.
The getColumns() method contains columns of SQL tables and files which are acces-
sible by JDBC.
See “Restrictions and Limitations” on page 5-22 for a list of methods that are not
supported by the IBM JDBC Driver for UniData and UniVerse and should not be
used in your Java program.
5-7 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
The Statement interface allows most of the eligible SQL statements to be executed,
according to the syntax of SQL statements supported by UniData and UniVerse SQL
servers. See “Restrictions and Limitations” on page 5-22 for a list of the unsupported
Statement methods
The ResultSetMetaData interface will return each column’s definition. For a map of
supported data types between UniData, UniVerse, and JDBC, see “Mapping Data
Types” on page 5-9.
5-8
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Mapping between JDBC API data types and UniData and UniVerse data
types.
ResultSet.getXXX() methods supported by the IBM JDBC Driver for
UniData and UniVerse.
The following table shows the UniData and UniVerse data types to which each JDBC
API data type maps. See “Restrictions and Limitations” on page 5-22 for a list of
unsupported data types.
JDBC API Data Type UniData Data Type UniVerse Data Type
5-9 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Data Conversion
Since UniData and UniVerse store all of their data types as strings, their respective
SQL servers will translate any column data that does not match to their data types to
NULL. Using a UniData or UniVerse data type that maps to a JDBC data type, such
as BIT, will work as long as the data stays within the range of the SQL server’s data
range.
5-10
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Handling Errors
IBM JDBC Driver for UniData and UniVerse error and warning messages (excep-
tions) can be generated from both the server and driver (client) sides.
All of the server side errors and warning messages contain SQLSTATE code and
original message text, whereas the driver side errors and warning messages may
contain vendor code, SQLSTATE code, and original message text.
Note: Run-time errors occuring in UniBasic and UVBasic subroutines are not
automatically propogated to the JDBC application. You can define an out parameter
for the subroutine to notify the JDBC application of UniBasic or UVBasic errors. The
JDBC application can then check the status of this paramter after calling the
subroutine.
5-11 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Handling Transactions
When you create a new Connection object, autocommit is set to true by default. This
means that when a statement is sent to the server, a COMMIT statement is automat-
ically executed. The autocommit mode can be set to true or false by calling the
Connection.setAutoCommit() method. The syntax is as follows:
Connection.setAutoCommit(true)
Connection.setAutoCommit(false)
If autocommit is set to false, the IBM JDBC Driver for UniData and UniVerse starts
a new transaction as soon as the next statement is sent to the database server. This
transaction lasts until a COMMIT or ROLLBACK statement is issued by the user. If
the user has already started a transaction by executing setAutoCommit(false), and
then calls setAutoCommit(false) again, the existing transaction continues unchanged.
In order for the connection to the database or database server to be dropped, the Java
program must explicitly terminate the transaction by issuing either a COMMIT or a
ROLLBACK statement.
While inside a transaction, if the Java program sets autocommit mode on, the IBM
JDBC Driver for UniData and UniVerse will roll back the current transaction before
it actually turns autocommit mode on.
If a COMMIT statement is sent to a database that has been created with logging, and
autocommit mode is on, the database server returns the error -255 : not in
transaction . This is true whether the statement was sent with the
Connection.commit() method, or directly with an SQL statement. This is true
because there is currently no user transaction started.
When you explicitly send a COMMIT statement to the database server in a database
created in ANSI mode, the statement commits an empty transaction. The system does
not return an error since the database server automatically starts a transaction before
it executes the statement. This is true if there is no user transaction currently open.
5-12
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Isolation Levels
UniData and Universe support the following isolation levels:
TRANSACTION_READ_UNCOMMITTED
TRANSACTION_READ_COMMITTED
TRANSACTION_REPEATABLE_READ
TRANSACTION_SERIALIZABLE
When changing the isolation level in manual transaction mode, the new isolation
level does not take effect until the current transaction has been committed or rolled
back.
5-13 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
In order to create a connection with the DataSource object, you must have the appro-
priate JNDI (Java Naming and Directory Interface) installed and configured for your
application. For more information on JNDI, go to:
http://java.sun.com/products/jndi
5-14
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
ds.setServerHost(“myServer”);
ds.setAccount(“myAccount”);
3. Now you must register the DataSource object by using the JNDI to map a
logical name to the DataSource object.
Now you can use the DataSource Object as shown in the following example:
Connection con = null;
try {
DataSource ds = (DataSource)ctx.lookup("myDS");
} catch (Exception e) {
// exception-handling code
} finally {
5-15 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
In situations where the application services frequent connection requests, using the
ConnectionPoolDataSource can significantly improve performance.
5-16
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Note: The username and Password parameters must be set in order for the
InitPoolsize parameter to take affect.
3. Now you must register the ConnectionPoolDataSource object by using the
JNDI to map a logical name to the ConnectionPoolDataSource object.
Context ctx = new InitialContext();
ctx.bind(“myCPDS”cpds,);
4. Now instantiate a UniJDBCDataSource object.
5. You must associate this DataSource object with the logical name you regis-
tered for the ConnectionPoolDataSource object:
ds.setDataSourceName(“myCPDS”);
6. Register the DataSource object using the JNDI interface:
Context ctx = new InitialContext();
ctx.bind(“DS_Pool”,ds);
5-17 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Now you can use the DataSource object, as shown in the following example:
Connection con = null;
try {
DataSource ds = (DataSource)ctx.lookup("DS_pool");
} catch (Exception e) {
// exception-handling code
} finally {
5-18
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Defaul
Parameter Description t
5-19 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Defaul
Parameter Description t
5-20
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
Defaul
Parameter Description t
5-21 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
java.sql.Types.ARRAY
java.sql.Types.BINARY
java.sql.Types.BLOB
java.sql.Types.CLOB
java.sql.Types.DISTINCT
java.sql.Types.JAVA_OBJECT
java.sql.Types.LONGVARBINARY
java.sql.Types.NULL
java.sql.Types.REF
java.sql.Types.STRUCT
java.sql.Types.TIMESTAMP
java.sql.Types.VARBINARY
Unsupported Methods
The IBM JDBC Driver for UniData and UniVerse does not support the following
JDBC functionality:
Statement.addBatch(string)
Statement.cancel()
Statement.clearBatch()
Statement.executeBatch()
PreparedStatement.addBatch()
5-22
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH05.fm
3/8/10
PreparedStatement.setArray(int, java.sql.Array)
PreparedStatement.setBlob(int, java.sql.Blob)
PreparedStatement.setCharacterStream(int, java.io.Reader)
PreparedStatement.setClob(int, java.sql.Clob)
PreparedStatement.setRef(int, java.sql.Ref)
Connection.getCatalog
Connection.setCatalog
Connection.getTypeMap
Connection.setTypeMap
5-23 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
ResultSet.getCharacterStream(int)
ResultSet.getCharacterStream(String)
ResultSetMetadata.getColumnClassName(int)
5-24
Chapter
PreparedStatement pstmt =
con.prepareStatement(sql,resultSetType,resultSetConcurrency)
CallableStatement cstmt =
con.prepareCall(sql,resultSetType,resultSetConcurrency)
resultSetType
The resultSetType parameter can be one of the types described in the following table.
resultSetType Description
TYPE_FORWARD_ONLY The cursor can only move forward in the result set.
resultSetConcurrency
The only valid valid for the resultSetConcurrency parameter is
CONCUR_READ_ONLY, for a resultSet object that can not be updated.
6-2
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH06.fm
3/8/10
Method Description
srs.afterLast() Move the cursor to the position after the last row, so the
following previous() method points to the last row.
srs.beforeFirst() Moves the cursor to the position before the first row.
srs.absolute(-n) Moves the cursor back n rows from the end of the result set.
srs.relative(n) Moves the cursor forward n rows from the current cursor
position.
srs.relative(-n) Moves the cursor back n rows from the current cursor position.
Methods for Moving the Cursor
6-3 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Parameter Description
6-4
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH06.fm
3/8/10
Example
The following example illustrates creating a scrollable cursor.
========================================================================
Example - Select
========================================================================
import java.sql.*;
try {
String MyHost = "localhost";
String MyAccount = "HS.SALES";
String userid = "username";
String passwd = "password";
// generate URL
String url = "jdbc:ibm-u2://" + MyHost + "/" + MyAccount ;
rs.absolute(10);
System.out.println(“pos = “ + rs.getRow + “@ID = “
+ rs.getString(@ID”));
rs.relative(-2) ;
System.out.println(“pos = “ + rs.getRow + “@ID = “
+ rs.getString(@ID”));
rs.next() ;
System.out.println(“pos = “ + rs.getRow + “@ID = “
+ rs.getString(@ID”));
rs.previous() ;
System.out.println(“pos = “ + rs.getRow + “@ID = “
+ rs.getString(@ID”));
rs.close() ;
stmt.close() ;
System.out.println( “End of SC query test.”) ;
con.close();
}
catch ( SQLException e ) {
System.out.println("Ex-Message :" + e.getMessage());
6-5 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
6-6
Chapter
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
This chapter provides some sample programs with comments throughout, describing
the use of some of the methods of the IBM JDBC Driver for UniData and UniVerse.
7-2
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH07.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
/**
* A sample program to test the IBM JDBC Driver for UniData and UniVerse.
*/
public class jdbcsample {
//---------------------------
// Connect to the U2 server
//---------------------------
// Get password
System.out.println("Enter password for user: ");
String passwd = in.readLine();
// generate URL
String url = "jdbc:ibm-
u2://"+host+"/"+account+"?dbmstype="+dbmstype;
//------------------------
7-3 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
// First example
//------------------------
System.out.println("1. Select from CUSTOMER -----------------------
-");
testQuery( con ) ;
//------------------------
// Second example
//------------------------
System.out.println("2. Transaction test ---------------------------
-");
testRollback( con ) ;
con.close();
} catch ( SQLException e ) {
System.out.println("Ex-Message :" + e.getMessage());
System.out.println("Ex-Code :" + e.getErrorCode()) ;
System.out.println("Ex-SQLState:" + e.getSQLState());
System.out.println("Ex-Next :" + e.getNextException());
e.printStackTrace() ;
System.gc();
} catch ( Exception e) {
System.out.println("Exception caught:"+e) ;
e.printStackTrace() ;
}
}
/**
* Select something from CUSTOMER table.
* @param con The JDBC connection object.
*/
public static void testQuery(Connection con)
throws SQLException
{
Statement stmt = con.createStatement();
String sql = "select @ID, CITY, STATE, ZIP, PHONE from CUSTOMER";
rs.close();
stmt.close() ;
System.out.println("\n*--- QUERY test is done successful ---*\n");
}
7-4
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH07.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
/**
* Transaction test. It will:
* (1) begin a transaction
* (2) update STATE of CUSTOMER to CA
* (3) re-read that record to show the update
* (4) roll the transaction back
* (5) re-read that record to show original value
* @param con The JDBC connection object.
*/
static public void testRollback(Connection con)
throws SQLException
{
System.out.println("\nThis section will:");
System.out.println("(1) begin a transaction");
System.out.println("(2) update STATE of CUSTOMER to CA");
System.out.println("(3) re-read that record to show the update");
System.out.println("(4) roll the transaction back");
System.out.println("(5) re-read that record to show original value\n");
pstmt.setString(1, "2");
ResultSet rs = pstmt.executeQuery() ;
while (rs.next())
{
System.out.println("updated STATE is " + rs.getString(1));
}
pstmt.close();
pstmt.setString(1, "2");
rs = pstmt.executeQuery() ;
while (rs.next())
{
System.out.println("original STATE is " + rs.getString(1));
}
7-5 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
pstmt.close() ;
7-6
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH07.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
Select Example
========================================================================
Example - Select
========================================================================
import java.sql.*;
try {
String MyHost = "localhost";
String MyAccount = "HS.SALES";
String userid = "username";
String passwd = "password";
// generate URL
String url = "jdbc:ibm-u2://" + MyHost + "/" + MyAccount ;
7-7 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
}
}
7-8
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH07.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
import java.sql.*;
try {
String MyHost = "localhost";
String MyAccount = "HS.SALES";
String userid = "username";
String passwd = "password";
// generate URL
String url = "jdbc:ibm-u2://" + MyHost + "/" + MyAccount ;
7-9 Using the IBM JDBC Driver for UniData and UniVerse
C:\Program
Files\Adobe\FrameMaker8\UniData
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
import java.sql.*;
try {
String MyHost = "localhost";
String MyAccount = "HS.SALES";
String userid = "username";
String passwd = "password";
// generate URL
String url = "jdbc:ibm-u2://" + MyHost + "/" + MyAccount ;
7-10
C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\JDBC\JDBCCH07.fm
3/8/10
Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta
import java.sql.*;
try {
String MyHost = "localhost";
String MyAccount = "HS.SALES";
String MySchema = null;
String MyTable = "CUSTOMER";
String userid = "username";
String passwd = "password";
// generate URL
String url = "jdbc:ibm-u2://" + MyHost + "/" + MyAccount ;
7-11 Using the IBM JDBC Driver for UniData and UniVerse