JDBC
JDBC
Trademarks
c-treeACE, c-treeRTG, c-treeAMS, c-tree Plus, c-tree, r-tree, FairCom and FairCom’s circular disc logo are trademarks of FairCom, registered
in the United States and other countries.
The following are third-party trademarks: AMD and AMD Opteron are trademarks of Advanced Micro Devices, Inc. Macintosh, Mac OS, and
Xcode are trademarks of Apple Inc., registered in the U.S. and other countries. Embarcadero, the Embarcadero Technologies logos and all
other Embarcadero Technologies product or service names are trademarks, service marks, and/or registered trademarks of Embarcadero
Technologies, Inc. and are protected by the laws of the United States and other countries. Business Objects and the Business Objects logo,
BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services
mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects Software Ltd. Business
Objects is an SAP company. DBstore is a trademark of Dharma Systems, Inc. HP and HP-UX are registered trademarks of the
Hewlett-Packard Company. AIX, IBM, OS/2, OS/2 WARP, Power 6 and POWER7 are trademarks or registered trademarks of International
Business Machines Corporation in the United States, other countries, or both. Intel, Itanium, Pentium and Xeon are trademarks or registered
trademarks of Intel Corporation or its subsidiaries in the United States and other countries. LynuxWorks, LynxOS and BlueCat are registered
trademarks of LynuxWorks, Inc. Microsoft, the .NET logo, MS-DOS, Windows, Windows Mobile, Windows NT, Windows Server, Windows
Vista, Visual Basic, and Visual Studio, are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or
other countries. Novell, NetWare, and SUSE are registered trademarks of Novell, Inc., in the United States and other countries. Oracle and
Java are registered trademarks of Oracle and/or its affiliates. QNX and Neutrino are registered trademarks of QNX Software Systems Ltd. in
certain jurisdictions. Red Hat and the Shadow Man logo are registered trademarks of Red Hat, Inc. in the United States and other countries,
used with permission. SCO and SCO Open Server are trademarks or registered trademarks of The SCO Group, Inc. in the U.S.A. and other
countries. SGI and IRIX are registered trademarks of Silicon Graphics, Inc., in the United States and/or other countries worldwide. UNIX and
UnixWare are registered trademarks of The Open Group in the United States and other countries. Linux is a trademark of Linus Torvalds in
the United States, other countries, or both. Python and PyCon are trademarks or registered trademarks of the Python Software Foundation.
All other trademarks, trade names, company names, product names, and registered trademarks are the property of their respective holders.
FairCom welcomes your comments on this document and the software it describes. Send comments using the contact form:
www.faircom.com/contact (http://www.faircom.com/contact).
Portions © 1987-2014 Dharma Systems, Inc. All rights reserved. This software or web site utilizes or contains material that is © 1994-2007
DUNDAS DATA VISUALIZATION, INC. and its licensors, all rights reserved.
Portions Copyright © 1995-2013 Jean-loup Gailly and Mark Adler.
1/13/2015
Contents
Introduction .......................................................................................................................................................... 1
1.1 Overview ................................................................................................................................................... 1
1.2 JDBC Architecture .................................................................................................................................... 1
1.3 Types of JDBC Drivers ............................................................................................................................. 2
JDBC-ODBC Bridge Drivers ..................................................................................................................... 2
Native-Method Drivers .............................................................................................................................. 3
Network-Protocol All-Java Drivers ............................................................................................................ 3
Native-Protocol All-Java Drivers (c-treeSQL JDBC Driver) ...................................................................... 3
1.4 JDBC Compared to ODBC ....................................................................................................................... 3
www.faircom.com
All Rights Reserved
iii
Table of Contents
Glossary .................................................................................................................................................................. 67
Index ........................................................................................................................................................................ 75
FairCom Corporation
Copyright 2015 FairCom Corporation
iv
FairCom Typographical Conventions
Before you begin using this guide, be sure to review the relevant terms and typographical
conventions used in the documentation.
The following formatted items identify special information.
www.faircom.com
All Rights Reserved
v
Chapter 1
Introduction
1.1 Overview
The c-treeACE SQL JDBC Driver provides access to c-treeACE SQL environments from applications
that support the JDBC 4.0 API (and requires JRE/JDK 1.6).
JDBC allows applications to connect to any database using the same set of Java interfaces. Those
interfaces allow programs to embed standard Structured Query Language (SQL) statements that
update and retrieve data in the database.
Because the Java interfaces and SQL syntax are independent of any particular database
implementation, JDBC makes it feasible for applications to connect to different database
environments without any modification.
www.faircom.com
All Rights Reserved
1
Chapter 1
Introduction
The following figure shows the different components of the JDBC architecture.
Figure 1: JDBC Architecture
FairCom Corporation
Copyright 2015 FairCom Corporation
2
c-treeSQL
JDBC Developer's Guide
Native-Method Drivers
Type 2 drivers contain Java code that calls “native” C or C++ methods already implemented by
database vendors.
Like an ODBC driver, a native-method driver must be installed on each client or server that uses it,
and thus has the same limitations as the JDBC-ODBC bridge drivers. A typical use of native-method
drivers is on application servers.
www.faircom.com
All Rights Reserved
3
Chapter 2
Quick Tour
www.faircom.com
All Rights Reserved
5
Chapter 2
Quick Tour
Initialize();
Define();
Manage();
Done();
FairCom Corporation
Copyright 2015 FairCom Corporation
6
c-treeSQL
JDBC Developer's Guide
Init
First we need to open a connection to a database by providing the c-treeACE Database Engine with a
user name, password and the database name.
Below is the code for Initialize():
//
// Initialize()
//
// Perform the minimum requirement of logging onto the c-tree Server
//
private static void Initialize ()
{
System.out.println("INIT");
try
{
// load the driver
Class.forName ("ctree.jdbc.ctreeDriver");
// connect to server
System.out.println("\tLogon to server...");
conn = DriverManager.getConnection ("jdbc:ctree:6597@localhost:ctreeSQL", "ADMIN",
"ADMIN");
www.faircom.com
All Rights Reserved
7
Chapter 2
Quick Tour
Define
The Define() step is where specific data definitions are established by your application and/or
process. This involves defining columns/fields and creating the tables/files with optional indices.
Below is the code for Define():
//
// Define()
//
// Create the table for containing a list of existing customers
//
private static void Define ()
{
System.out.println("DEFINE");
try
{
// create table
System.out.println("\tCreate table...");
stmt.executeUpdate("CREATE TABLE custmast (" +
"cm_custnumb CHAR(4), " +
"cm_custzipc CHAR(9), " +
"cm_custstat CHAR(2), " +
"cm_custrtng CHAR(1), " +
"cm_custname VARCHAR(47), " +
"cm_custaddr VARCHAR(47), " +
"cm_custcity VARCHAR(47))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
8
c-treeSQL
JDBC Developer's Guide
Manage
The manage step provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// This function performs simple record functions of add, delete and gets
//
private static void Manage ()
{
System.out.println("MANAGE");
//
// Delete_Records()
//
// This function deletes all the records in the table
//
private static void Delete_Records ()
{
System.out.println("\tDelete records...");
try
{
stmt.executeUpdate("DELETE FROM custmast");
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_Records()
//
// This function adds records to a table in the database from an
// array of strings
//
private static void Add_Records ()
{
System.out.println("\tAdd records...");
www.faircom.com
All Rights Reserved
9
Chapter 2
Quick Tour
String data[] = {
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
};
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO custmast VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Display_Records()
//
// This function displays the contents of a table.
//
private static void Display_Records ()
{
System.out.print("\tDisplay records...");
try
{
// execute a query statement
ResultSet rs = stmt.executeQuery ("SELECT * FROM custmast");
FairCom Corporation
Copyright 2015 FairCom Corporation
10
c-treeSQL
JDBC Developer's Guide
Done
When an application and/or process has completed operations with the database, it must release
resources by disconnecting from the database engine.
Below is the code for Done():
//
// Done()
//
// This function handles the housekeeping of closing, freeing,
// disconnecting and logging out of the database
//
private static void Done ()
{
System.out.println("DONE");
try
{
stmt.close();
// logout
System.out.println("\tLogout...");
conn.close();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
www.faircom.com
All Rights Reserved
11
Chapter 2
Quick Tour
Additional Resources
FairCom Corporation
Copyright 2015 FairCom Corporation
12
c-treeSQL
JDBC Developer's Guide
2.2 Relationships
..\sdk\sql.jdbc\tutorials\JDBC_Tutorial2.java
Now we will build some table/file relationships using the c-treeACE SQL JDBC Interface.
This tutorial will advance the concepts introduced in the first tutorial by expanding the number of
tables. We will define key columns/fields and create specific indices for each table to form a relational
model database.
Like all other examples in the c-tree tutorial series, this tutorial simplifies the creation and use of a
database into four simple steps: Initialize(), Define(), Manage(), and You’re Done() !
www.faircom.com
All Rights Reserved
13
Chapter 2
Quick Tour
Manage();
Done();
FairCom Corporation
Copyright 2015 FairCom Corporation
14
c-treeSQL
JDBC Developer's Guide
Init
First we need to open a connection to a database by providing the c-treeACE Database Engine with a
user name, password and the database name.
Below is the code for Initialize():
//
// Initialize()
//
// Perform the minimum requirement of logging onto the c-tree Server
//
private static void Initialize ()
{
System.out.println("INIT");
try
{
// load the driver
Class.forName ("ctree.jdbc.ctreeDriver");
// connect to server
System.out.println("\tLogon to server...");
conn = DriverManager.getConnection ("jdbc:ctree:6597@localhost:ctreeSQL", "ADMIN",
"ADMIN");
www.faircom.com
All Rights Reserved
15
Chapter 2
Quick Tour
Define
The Define() step is where specific data definitions are established by your application and/or
process. This involves defining columns/fields and creating the tables/files with optional indices.
Below is the code for Define():
//
// Define()
//
// Create the tables
//
private static void Define ()
{
System.out.println("DEFINE");
Create_CustomerMaster_Table();
Create_CustomerOrders_Table();
Create_OrderItems_Table();
Create_ItemMaster_Table();
}
//
// Create_CustomerMaster_Table()
//
// Create the table CustomerMaster
//
private static void Create_CustomerMaster_Table ()
{
// define table CustomerMaster
System.out.println("\ttable CustomerMaster");
try
{
stmt.executeUpdate("CREATE TABLE custmast (" +
"cm_custnumb CHAR(4), " +
"cm_custzipc CHAR(9), " +
"cm_custstat CHAR(2), " +
"cm_custrtng CHAR(1), " +
"cm_custname VARCHAR(47), " +
"cm_custaddr VARCHAR(47), " +
"cm_custcity VARCHAR(47))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("CREATE UNIQUE INDEX cm_custnumb_idx ON custmast (cm_custnumb)");
}
catch (SQLException e)
{
FairCom Corporation
Copyright 2015 FairCom Corporation
16
c-treeSQL
JDBC Developer's Guide
Handle_Exception(e);
}
}
//
// Create_CustomerOrders_Table()
//
// Create the table CustomerOrders
//
private static void Create_CustomerOrders_Table ()
{
// define table CustomerOrders
System.out.println("\ttable CustomerOrders");
try
{
stmt.executeUpdate("CREATE TABLE custordr (" +
"co_ordrdate DATE, " +
"co_promdate DATE, " +
"co_ordrnumb CHAR(6), " +
"co_custnumb CHAR(4))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("CREATE UNIQUE INDEX co_ordrnumb_idx ON custordr (co_ordrnumb)");
stmt.executeUpdate("CREATE INDEX co_custnumb_idx ON custordr (co_custnumb)");
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Create_OrderItems_Table()
//
// Create the table OrderItems
//
private static void Create_OrderItems_Table ()
{
// define table OrderItems
System.out.println("\ttable OrderItems");
try
{
stmt.executeUpdate("CREATE TABLE ordritem (" +
"oi_sequnumb SMALLINT, " +
"oi_quantity SMALLINT, " +
"oi_ordrnumb CHAR(6), " +
"oi_itemnumb CHAR(5))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("CREATE UNIQUE INDEX oi_ordrnumb_idx ON ordritem (oi_ordrnumb,
oi_sequnumb)");
stmt.executeUpdate("CREATE INDEX oi_itemnumb_idx ON ordritem (oi_itemnumb)");
}
www.faircom.com
All Rights Reserved
17
Chapter 2
Quick Tour
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Create_ItemMaster_Table()
//
// Create the table ItemMaster
//
private static void Create_ItemMaster_Table ()
{
// define table ItemMaster
System.out.println("\ttable ItemMaster");
try
{
stmt.executeUpdate("CREATE TABLE itemmast (" +
"im_itemwght INTEGER, " +
"im_itempric MONEY, " +
"im_itemnumb CHAR(5), " +
"im_itemdesc VARCHAR(47))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("CREATE UNIQUE INDEX im_itemnumb_idx ON itemmast (im_itemnumb)");
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
18
c-treeSQL
JDBC Developer's Guide
Manage
The manage step provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// Populates table and perform a simple query
//
private static void Manage ()
{
System.out.println("MANAGE");
// perform a query:
// list customer name and total amount per order
// name total
// @@@@@@@@@@@@@ $xx.xx
System.out.println("\n\tQuery Results");
try
{
ResultSet rs = stmt.executeQuery (
"SELECT cm_custname, SUM(im_itempric * oi_quantity) " +
"FROM custmast, custordr, ordritem, itemmast " +
"WHERE co_custnumb = cm_custnumb AND co_ordrnumb = oi_ordrnumb AND oi_itemnumb =
im_itemnumb " +
"GROUP BY cm_custnumb, cm_custname");
// read resultset
while (rs.next())
{
// fetch customer name
String custname = rs.getString(1);
www.faircom.com
All Rights Reserved
19
Chapter 2
Quick Tour
rs.close();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_CustomerMaster_Records()
//
// This function adds records to table CustomerMaster from an
// array of strings
//
private static void Add_CustomerMaster_Records ()
{
System.out.println("\tAdd records in table CustomerMaster...");
String data[] = {
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
};
Delete_Records("custmast");
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO custmast VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_CustomerOrders_Records()
//
// This function adds records to table CustomerOrders from an
// array of strings
//
private static void Add_CustomerOrders_Records ()
{
System.out.println("\tAdd records in table CustomerOrders...");
String data[] = {
"('09/01/2002','09/05/2002','1','1001')",
"('09/02/2002','09/06/2002','2','1002')"
};
Delete_Records("custordr");
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO custordr VALUES " + data[i]);
FairCom Corporation
Copyright 2015 FairCom Corporation
20
c-treeSQL
JDBC Developer's Guide
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_OrderItems_Records()
//
// This function adds records to table OrderItems from an
// array of strings
//
private static void Add_OrderItems_Records ()
{
System.out.println("\tAdd records in table OrderItems...");
String data[] = {
"(1,2,'1','1')",
"(2,1,'1','2')",
"(3,1,'1','3')",
"(1,3,'2','3')"
};
Delete_Records("ordritem");
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO ordritem VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_ItemMaster_Records()
//
// This function adds records to table ItemMaster from an
// array of strings
//
private static void Add_ItemMaster_Records ()
{
System.out.println("\tAdd records in table ItemMaster...");
String data[] = {
"(10,19.95,'1','Hammer')",
"(3, 9.99,'2','Wrench')",
"(4, 16.59,'3','Saw')",
"(1, 3.98,'4','Pliers')"
};
Delete_Records("itemmast");
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO itemmast VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
www.faircom.com
All Rights Reserved
21
Chapter 2
Quick Tour
}
}
//
// Delete_Records()
//
// This function deletes all the records in a tables
//
private static void Delete_Records (String table)
{
System.out.println("\tDelete records...");
try
{
stmt.executeUpdate("DELETE FROM " + table);
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
22
c-treeSQL
JDBC Developer's Guide
Done
When an application and/or process has completed operations with the database, it must release
resources by disconnecting from the database engine.
Below is the code for Done():
//
// Done()
//
// This function handles the housekeeping of closing, freeing,
// disconnecting and logging out of the database
//
private static void Done ()
{
System.out.println("DONE");
try
{
stmt.close();
// logout
System.out.println("\tLogout...");
conn.close();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
www.faircom.com
All Rights Reserved
23
Chapter 2
Quick Tour
Additional Resources
FairCom Corporation
Copyright 2015 FairCom Corporation
24
c-treeSQL
JDBC Developer's Guide
www.faircom.com
All Rights Reserved
25
Chapter 2
Quick Tour
FairCom Corporation
Copyright 2015 FairCom Corporation
26
c-treeSQL
JDBC Developer's Guide
Init
First we need to open a connection to a database by providing the c-treeACE Database Engine with a
user name, password and the database name.
Below is the code for Initialize():
//
// Initialize()
//
// Perform the minimum requirement of logging onto the c-tree Server
//
private static void Initialize ()
{
System.out.println("INIT");
try
{
// load the driver
Class.forName ("ctree.jdbc.ctreeDriver");
// connect to server
System.out.println("\tLogon to server...");
conn = DriverManager.getConnection ("jdbc:ctree:6597@localhost:ctreeSQL", "ADMIN",
"ADMIN");
www.faircom.com
All Rights Reserved
27
Chapter 2
Quick Tour
Define
The Define() step is where specific data definitions are established by your application and/or
process. This involves defining columns/fields and creating the tables/files with optional indices.
Below is the code for Define():
//
// Define()
//
// Create the table for containing a list of existing customers
//
private static void Define ()
{
System.out.println("DEFINE");
try
{
// create table
System.out.println("\tCreate table...");
stmt.executeUpdate("CREATE TABLE custmast (" +
"cm_custnumb CHAR(4), " +
"cm_custzipc CHAR(9), " +
"cm_custstat CHAR(2), " +
"cm_custrtng CHAR(1), " +
"cm_custname VARCHAR(47), " +
"cm_custaddr VARCHAR(47), " +
"cm_custcity VARCHAR(47))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("CREATE UNIQUE INDEX cm_custnumb_idx ON custmast (cm_custnumb)");
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
28
c-treeSQL
JDBC Developer's Guide
Manage
The manage step provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// This function performs record adds and updates using locking
//
private static void Manage ()
{
System.out.println("MANAGE");
//
// Delete_Records()
//
// This function deletes all the records in the table
//
private static void Delete_Records ()
{
System.out.println("\tDelete records...");
try
{
stmt.executeUpdate("DELETE FROM custmast");
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
www.faircom.com
All Rights Reserved
29
Chapter 2
Quick Tour
}
}
//
// Add_CustomerMaster_Records()
//
// This function adds records to table CustomerMaster from an
// array of strings
//
private static void Add_CustomerMaster_Records ()
{
System.out.println("\tAdd records...");
String data[] = {
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
};
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO custmast VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Display_Records()
//
// This function displays the contents of a table.
//
private static void Display_Records ()
{
System.out.print("\tDisplay records...");
try
{
// execute a query statement
ResultSet rs = stmt.executeQuery ("SELECT * FROM custmast");
//
FairCom Corporation
Copyright 2015 FairCom Corporation
30
c-treeSQL
JDBC Developer's Guide
// Update_CustomerMaster_Records()
//
// Update one record under locking control to demonstrate the effects
// of locking
//
private static void Update_CustomerMaster_Record()
{
System.out.println("\tUpdate record...");
try
{
stmt.executeUpdate("UPDATE custmast SET cm_custname = 'KEYON DOOLING' where cm_custnumb
= '1003'");
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
catch (Exception e)
{
Handle_Exception(e);
}
}
www.faircom.com
All Rights Reserved
31
Chapter 2
Quick Tour
Done
When an application and/or process has completed operations with the database, it must release
resources by disconnecting from the database engine.
Below is the code for Done():
//
// Done()
//
// This function handles the housekeeping of closing, freeing,
// disconnecting and logging out of the database
//
private static void Done ()
{
System.out.println("DONE");
try
{
stmt.close();
// logout
System.out.println("\tLogout...");
conn.close();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
32
c-treeSQL
JDBC Developer's Guide
Additional Resources
www.faircom.com
All Rights Reserved
33
Chapter 2
Quick Tour
FairCom Corporation
Copyright 2015 FairCom Corporation
34
c-treeSQL
JDBC Developer's Guide
Init
First we need to open a connection to a database by providing the c-treeACE Database Engine with a
user name, password and the database name.
Below is the code for Initialize():
//
// Initialize()
//
// Perform the minimum requirement of logging onto the c-tree Server
//
private static void Initialize ()
{
System.out.println("INIT");
try
{
// load the driver
Class.forName ("ctree.jdbc.ctreeDriver");
// connect to server
System.out.println("\tLogon to server...");
conn = DriverManager.getConnection ("jdbc:ctree:6597@localhost:ctreeSQL", "ADMIN",
"ADMIN");
www.faircom.com
All Rights Reserved
35
Chapter 2
Quick Tour
Define
The Define() step is where specific data definitions are established by your application and/or
process. This involves defining columns/fields and creating the tables/files with optional indices.
Below is the code for Define():
//
// Define()
//
// Create the tables
//
private static void Define ()
{
System.out.println("DEFINE");
//
// Create_CustomerMaster_Table()
//
// Create the table CustomerMaster
//
private static void Create_CustomerMaster_Table ()
{
// define table CustomerMaster
System.out.println("\ttable CustomerMaster");
try
{
stmt.executeUpdate("CREATE TABLE custmast (" +
"cm_custnumb CHAR(4) PRIMARY KEY, " +
"cm_custzipc CHAR(9), " +
"cm_custstat CHAR(2), " +
"cm_custrtng CHAR(1), " +
"cm_custname VARCHAR(47), " +
"cm_custaddr VARCHAR(47), " +
"cm_custcity VARCHAR(47))"
);
}
FairCom Corporation
Copyright 2015 FairCom Corporation
36
c-treeSQL
JDBC Developer's Guide
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Create_CustomerOrders_Table()
//
// Create the table CustomerOrders
//
private static void Create_CustomerOrders_Table ()
{
// define table CustomerOrders
System.out.println("\ttable CustomerOrders");
try
{
stmt.executeUpdate("CREATE TABLE custordr (" +
"co_ordrdate DATE, " +
"co_promdate DATE, " +
"co_ordrnumb CHAR(6) PRIMARY KEY, " +
"co_custnumb CHAR(4), " +
"FOREIGN KEY (co_custnumb) REFERENCES custmast)"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Create_OrderItems_Table()
//
// Create the table OrderItems
//
private static void Create_OrderItems_Table ()
{
// define table OrderItems
System.out.println("\ttable OrderItems");
try
{
stmt.executeUpdate("CREATE TABLE ordritem (" +
"oi_sequnumb SMALLINT, " +
"oi_quantity SMALLINT, " +
"oi_ordrnumb CHAR(6), " +
"oi_itemnumb CHAR(5), " +
"FOREIGN KEY (oi_itemnumb) REFERENCES itemmast, " +
"FOREIGN KEY (oi_ordrnumb) REFERENCES custordr)"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Create_ItemMaster_Table()
//
// Create the table ItemMaster
//
private static void Create_ItemMaster_Table ()
{
// define table ItemMaster
www.faircom.com
All Rights Reserved
37
Chapter 2
Quick Tour
System.out.println("\ttable ItemMaster");
try
{
stmt.executeUpdate("CREATE TABLE itemmast (" +
"im_itemwght INTEGER, " +
"im_itempric MONEY, " +
"im_itemnumb CHAR(5) PRIMARY KEY, " +
"im_itemdesc VARCHAR(47))"
);
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
38
c-treeSQL
JDBC Developer's Guide
Manage
The manage step provides data management functionality for your application and/or process.
Below is the code for Manage():
//
// Manage()
//
// Populates table and perform a simple query
//
private static void Manage ()
{
System.out.println("MANAGE");
Add_Transactions();
//
// Delete_Tables()
//
// This function removes all existing tables
//
private static void Delete_Tables ()
{
try
{
stmt.executeUpdate("DROP TABLE ordritem");
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("DROP TABLE custordr");
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.executeUpdate("DROP TABLE custmast");
}
catch (SQLException e)
{
www.faircom.com
All Rights Reserved
39
Chapter 2
Quick Tour
Handle_Exception(e);
}
try
{
stmt.executeUpdate("DROP TABLE itemmast");
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_CustomerMaster_Records()
//
// This function adds records to table CustomerMaster from an
// array of strings
//
private static void Add_CustomerMaster_Records ()
{
String data[] = {
"('1000','92867','CA','1','Bryan Williams','2999 Regency','Orange')",
"('1001','61434','CT','1','Michael Jordan','13 Main','Harford')",
"('1002','73677','GA','1','Joshua Brown','4356 Cambridge','Atlanta')",
"('1003','10034','MO','1','Keyon Dooling','19771 Park Avenue','Columbia')"
};
try
{
// add one record at time to table
for (int i = 0; i < data.length; i++) {
stmt.executeUpdate("INSERT INTO custmast VALUES " + data[i]);
}
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
//
// Add_ItemMaster_Records()
//
// This function adds records to table ItemMaster from an
// array of strings
//
private static void Add_ItemMaster_Records ()
{
String data[] = {
"(10,19.95,'1','Hammer')",
"(3, 9.99,'2','Wrench')",
"(4, 16.59,'3','Saw')",
"(1, 3.98,'4','Pliers')"
};
try
{
FairCom Corporation
Copyright 2015 FairCom Corporation
40
c-treeSQL
JDBC Developer's Guide
//
// Add_Transactions()
//
// Add an Order and associated Items "as a transaction" to their
// respective tables. A transaction is committed or aborted if the
// customer number on the order is confirmed valid. Likewise each
// item in the order is verified to be a valid item.
//
private static void Add_Transactions()
{
int i, j = 0;
String[][] orders = {
{ "09/01/2002", "09/05/2002", "1", "1001" },
{ "09/02/2002", "09/06/2002", "2", "9999" }, // bad customer number
{ "09/22/2002", "09/26/2002", "3", "1003" }
};
String[][] items = {
{ "1", "1", "2", "1" },
{ "1", "2", "1", "2" },
{ "2", "1", "1", "3" },
{ "2", "2", "3", "4" },
{ "3", "1", "2", "3" },
{ "3", "2", "2", "99"} // bad item number
};
www.faircom.com
All Rights Reserved
41
Chapter 2
Quick Tour
items[j][1] + "," +
items[j][2] + "," +
"'" + items[j][0] + "'," +
"'" + items[j][3] + "')");
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
}
//
// Display_CustomerOrders()
//
// This function displays the contents of CustomerOrders table.
//
private static void Display_CustomerOrders ()
{
System.out.println("\n\tCustomerOrders Table...");
try
{
// execute a query statement
ResultSet rs = stmt.executeQuery ("SELECT * FROM custordr");
//
// Display_OrderItems()
//
// This function displays the contents of OrderItems table.
//
private static void Display_OrderItems ()
{
System.out.println("\n\tOrderItems Table...");
try
{
// execute a query statement
ResultSet rs = stmt.executeQuery ("SELECT * FROM ordritem");
FairCom Corporation
Copyright 2015 FairCom Corporation
42
c-treeSQL
JDBC Developer's Guide
www.faircom.com
All Rights Reserved
43
Chapter 2
Quick Tour
Done
When an application and/or process has completed operations with the database, it must release
resources by disconnecting from the database engine.
Below is the code for Done():
//
// Done()
//
// This function handles the housekeeping of closing, freeing,
// disconnecting and logging out of the database
//
private static void Done ()
{
System.out.println("DONE");
Delete_Tables();
try
{
conn.commit();
}
catch (SQLException e)
{
Handle_Exception(e);
}
try
{
stmt.close();
// logout
System.out.println("\tLogout...");
conn.close();
}
catch (SQLException e)
{
Handle_Exception(e);
}
}
FairCom Corporation
Copyright 2015 FairCom Corporation
44
c-treeSQL
JDBC Developer's Guide
Additional Resources
www.faircom.com
All Rights Reserved
45
Chapter 3
3.1 Introduction
This chapter describes how to set up and get started using the c-treeACE SQL JDBC Driver.
www.faircom.com
All Rights Reserved
47
Chapter 3
Basic JDBC Driver Operations
<html>
<head>
<title>Test</title>
</head>
<body>
<p>
Here, in all its glory, is the ctreeJDBCApplet test applet!
<center>
<applet code="c-treeJDBCApplet.class"
archive="c-treeJDBCTest.jar" width=500 height=400>
<param name=Driver value="ctree.jdbc.ctreeDriver">
<param name=URL value="jdbc:ctree:6597@mydomain:ctreeSQL">
<param name=User value="ADMIN">
<param name=Password value="dummy">
</applet>
</center>
</body>
</html>
FairCom Corporation
Copyright 2015 FairCom Corporation
48
c-treeSQL
JDBC Developer's Guide
www.faircom.com
All Rights Reserved
49
Chapter 3
Basic JDBC Driver Operations
:port The port number associated with the c-treeACE SQL server on the host system.
FairCom Corporation
Copyright 2015 FairCom Corporation
50
c-treeSQL
JDBC Developer's Guide
An Example Connection
The following example shows a code excerpt that illustrates loading the driver and connecting to the
default server and database. The following example uses the form of
DriverManager.GetConnection() that takes authentication information as a single Properties object.
javax.sql Package
The c-treeACE SQL JDBC javax.sql package provides the APIs for server side data source access
and processing. This is included in the Java 2 SDK version 1.6, Standard Edition.
The javax.sql package provides the following:
The DataSource interface as an alternative to the DriverManager for establishing a connection
with a data source
Connection pooling
www.faircom.com
All Rights Reserved
51
Chapter 3
Basic JDBC Driver Operations
A particular DataSource object represents a particular physical data source, and each connection the
DataSource object creates is a connection to that physical data source. A DataSource object can be
implemented to work with the middle tier infrastructure so that the connections it produces will be
pooled for reuse. An application that uses such a DataSource implementation will automatically get a
connection that participates in connection pooling. A DataSource object can also be implemented to
work with the middle tier infrastructure so that the connections it produces can be used for distributed
transactions without any special coding.
Connection Pooling
Connections made via a DataSource object that is implemented to work with a middle tier connection
pool manager will participate in connection pooling. This can improve performance dramatically
because creating new connections is very expensive. Connection pooling allows a connection to be
used and reused, thus reducing the number of new connections that need to be created.
Connection pooling is totally transparent. It is done automatically in the middle tier of a J2EE
Environment, and hence from an application’s viewpoint, no change in code is required. An
application simply uses the DataSource.getConnection() method to get the pooled connection and
uses it the same way it uses any Connection object.
Note: In autocommit mode, the JDBC Driver does not issue a commit after SELECT and CALL
statements. The driver assumes these statements generate result sets and relies on the application
to explicitly commit or roll back the transaction after it processes any result set and closes the
statement.
You can change transaction mode to manual commit by calling the Connection.setAutoCommit()
method. In manual commit mode, applications must commit a transaction by using the
FairCom Corporation
Copyright 2015 FairCom Corporation
52
c-treeSQL
JDBC Developer's Guide
String query = “SELECT TOP 50000 FROM my_big_table WHERE this < that AND this_string = 'that_string'
ORDER BY foo”
myStatement:setQueryTimeout(5);
myStatement.executeUpdate(query);
Example
Properties info = new Properties();
info.setProperty("user","ADMIN");
info.setProperty("password","ADMIN");
info.setProperty("sock_timeout","30000");
conn = DriverManager.getConnection ("jdbc:ctree:6597@localhost:ctreeSQL", info);
www.faircom.com
All Rights Reserved
53
Chapter 3
Basic JDBC Driver Operations
FairCom Corporation
Copyright 2015 FairCom Corporation
54
Chapter 4
www.faircom.com
All Rights Reserved
55
Chapter 4
JDBC Conformance Notes
Many of the methods return lists of information as an object of type ResultSet. Use the normal
ResultSet methods such as getString() and getInt() to retrieve the data from the result sets.
Return Values for DatabaseMetaData Methods
FairCom Corporation
Copyright 2015 FairCom Corporation
56
c-treeSQL
JDBC Developer's Guide
getBestRowIdentifier(String, String, Get a description of a table’s optimal set of columns (result set)
String, int, boolean) that uniquely identifies a row.
getCatalogs() Get the catalog names available in this database. "Driver not capable"
getColumnPrivileges(String, String, Get a description of the access rights for a table’s (result set)
String, String) columns.
getColumns(String, String, String, Get a description of table columns available in a (result set)
String) catalog.
getCrossReference(String, String, Get a description of the foreign key columns in the (result set)
String, String, String, String) foreign key table that reference the primary key
columns of the primary key table (describe how one
table imports another’s key.) This should normally
return a single foreign key/primary key pair (most
tables only import a foreign key from a table once.)
They are ordered by FKTABLE_CAT,
FKTABLE_SCHEM, FKTABLE_NAME, and
KEY_SEQ.
getExportedKeys(String, String, Get a description of the foreign key columns that (result set)
String) reference a table’s primary key columns (the foreign
keys exported by a table).
getExtraNameCharacters() Get all the “extra” characters that can be used in null
unquoted identifier names (those beyond a-z, A-Z,
0-9 and _).
getImportedKeys(String, String, Get a description of the primary key columns that (result set)
String) are referenced by a table’s foreign key columns (the
primary keys imported by a table).
www.faircom.com
All Rights Reserved
57
Chapter 4
JDBC Conformance Notes
getMaxIndexLength() What’s the maximum length of an index (in bytes)? 0 (no limit)
FairCom Corporation
Copyright 2015 FairCom Corporation
58
c-treeSQL
JDBC Developer's Guide
getSearchStringEscape() This is the string that can be used to escape ‘_’ or “\”
‘%’ in the string pattern style catalog search
parameters.
getStringFunctions() Get a comma separated list of string functions. ASCII, LTRIM, CHAR,
DIFFERENCE,
INSERT, LCASE,
LEFT, REPEAT,
REPLACE,
SOUNDEX, SPACE,
SUBSTRING, UCASE,
RTRIM, CONCAT,
LENGTH, LOCATE,
TRIM
www.faircom.com
All Rights Reserved
59
Chapter 4
JDBC Conformance Notes
getTables(String, String, String, Get a description of tables available in a catalog. (result set)
String [])
getTableTypes() Get the table types available in this database. SYNONYM, SYSTEM
TABLE, TABLE, VIEW
FairCom Corporation
Copyright 2015 FairCom Corporation
60
c-treeSQL
JDBC Developer's Guide
getUserName() What’s our user name as known to the database? (the userid)
getVersionColumns(String, String, Get a description of a table’s columns that are (result set)
String) automatically updated when any value in a row is
updated.
isCatalogAtStart() Does a catalog appear at the start of a qualified True
table name? (Otherwise it appears at the end)
isReadOnly() Is the database in read-only mode? False
storesMixedCaseQuotedIdentifiers( Does the database treat mixed case quoted SQL False
) identifiers as case insensitive and store them in
mixed case?
storesUpperCaseIdentifiers() Does the database treat mixed case unquoted SQL True or False
identifiers as case insensitive and store them in
upper case? Depends on the
identifier case
specified during the
creation of database.
storesUpperCaseQuotedIdentifiers( Does the database treat mixed case quoted SQL False
) identifiers as case insensitive and store them in
upper case?
www.faircom.com
All Rights Reserved
61
Chapter 4
JDBC Conformance Notes
FairCom Corporation
Copyright 2015 FairCom Corporation
62
c-treeSQL
JDBC Developer's Guide
supportsGroupByBeyondSelect() Can a “GROUP BY” clause add columns not in the True
SELECT provided it specifies all the columns in the
SELECT?
supportsGroupByUnrelated() Can a “GROUP BY” clause use columns not in the False
SELECT?
supportsLimitedOuterJoins() Is there limited support for outer joins? (This will be True
true if supportFullOuterJoins is true.)
supportsOrderByUnrelated() Can an “ORDER BY” clause use columns not in the True
SELECT?
www.faircom.com
All Rights Reserved
63
Chapter 4
JDBC Conformance Notes
JDBC 2.0
FairCom Corporation
Copyright 2015 FairCom Corporation
64
c-treeSQL
JDBC Developer's Guide
getConnection() Retrieves the connection that produced this The connection that
metadata object. produced this
metadata object
getUDTs(String, String, String, int[]) Gets a description of the userdefined types defined Empty ResultSet
in a particular schema. object
supportsResultSetType(int) Does the database support the given result set True if result set type
type? is
FORWARD_ONLY
supportsResultSetConcurrency(int, Does the database support the concurrency type in True if result set type
int) combination with the given result set type? is FORWARD_ONLY
and if concurrency
type is
CONCUR_READ_ON
LY
updatesAreDetected(int) Indicates whether or not a visible row update can be False
detected by calling the method
ResultSet.rowUpdated.
JDBC 3.0
www.faircom.com
All Rights Reserved
65
Chapter 4
JDBC Conformance Notes
getAttributes(String, String, String, Gets a description of the given attribute of the given Empty ResultSet
String) type for a user-defined type that is available in the object
given schema and catalog
supportsResultSetHoldability(int) Does the database support the given result set True if result set
holdability holdability is ResultSet
.CLOSE_CURSORS_
AT_COMMIT,
otherwise False
getResultSetHoldability() Gets the default holdability of this ResultSet object Always returns
ResultSet.CLOSE_CU
RSORS_AT_COMMIT
getJDBCMinorVersion() Gets the minor JDBC version number of this driver returns 0
locatorsUpdateCopy() Indicates whether updates made to LOB are made “Driver does not
on a copy or directly to the LOB support this”Exception
FairCom Corporation
Copyright 2015 FairCom Corporation
66
c-treeSQL
JDBC Developer's Guide
Glossary
add [an ODBC data source]
Make a data source available to ODBC through the Add operation of the ODBC Administrator utility.
Adding a data source tells ODBC where a specific database resides and which ODBC driver to use to
access it. Adding a data source also invokes a setup dialog box for the particular driver so you can
provide other details the driver needs to connect to the database.
ADMIN
The default owner name for all system tables in a c-treeACE SQL database. Users must qualify
references to system tables as ADMIN.tablename.
alias
A temporary name for a table or column specified in the FROM clause of an SQL query expression.
Also called correlation name. Derived tables and search conditions that join a table with itself must
specify an alias. Once a query specifies an alias, references to the table or column must use the alias
and not the underlying table or column name.
applet
A special kind of Java program whose compiled class files a Java-enabled browser can download
from the Internet and run.
ASCII
(American Standard Code for Information Interchange) A 7-bit character set that provides 128
character combinations.
bytecode
Machine-independent code generated by the Java compiler and executed by the Java interpreter.
candidate key
Another term for unique key.
cardinality
Number of rows in a result table.
Cartesian product
Also called cross-product. In a query expression, the result table generated when a FROM clause
lists more than one table but specifies no join conditions. In such a case, the result table is formed by
concatenating every row of every table with all other rows in all tables. Typically, Cartesian products
are not useful and are slow to process.
client
www.faircom.com
All Rights Reserved
67
Chapter 4
Glossary
Generally, in client/server systems, the part of the system that sends requests to servers and
processes the results of those requests.
collation
The rules used to control how character strings in a character set compare with each other. Each
character set specifies a collating sequence that defines relative values of each character for
comparing, merging and sorting character strings.
column alias
An alias specified for a column. See alias.
constraint
Part of an SQL table definition that restricts the values that can be stored in a table. When you insert,
delete, or update column values, the constraint checks the new values against the conditions
specified by the constraint. If the value violates the constraint, it generates an error. Along with
triggers, constraints enforce referential integrity by insuring that a value stored in the foreign key of a
table must either be null or be equal to some value in the matching unique or primary key of another
table.
correlation name
Another term for alias.
cross product
Another term for Cartesian product.
data dictionary
Another term for system catalog.
data source
See ODBC data source.
derived table
A virtual table specified as a query expression in the FROM clause of another query expression.
driver manager
See JDBC driver manager and ODBC driver manager.
foreign key
A column or columns in a table whose values must either be null or equal to some value in a
corresponding column (called the primary key) in another table. Use the REFERENCES clause in the
SQL CREATE TABLE statement to create foreign keys.
form of use
The storage format for characters in a character set. Some character sets, such as ASCII, require
one byte (octet) for each character. Others, such as Unicode, use two bytes, and are called
multi-octet character sets.
input parameter
In a stored procedure specification, an argument that an application must pass when it calls the
stored procedure. In an SQL statement, a parameter marker in the statement string that acts as a
placeholder for a value that will be substituted when the statement executes.
interface
In Java, a definition of a set of methods that one or more objects will implement. Interfaces declare
only methods and constants, not variables. Interfaces provide multiple-inheritance capabilities.
FairCom Corporation
Copyright 2015 FairCom Corporation
68
c-treeSQL
JDBC Developer's Guide
Java snippet
See snippet.
JDBC
Java Database Connectivity: a part of the Java language that allows applications to embed standard
SQL statements and access any database that implements a JDBC driver.
JDBC driver
Database-specific software that receives calls from the JDBC driver manager, translates them into a
form that the database can process, and returns data to the application.
JDBC driver manager
A Java class that implements methods to route calls from a JDBC application to the appropriate
JDBC driver for a particular JDBC URL.
join
A relational operation that combines data from two tables.
main-memory storage system / storage manager
A storage system and storage manager supplied with c-treeSQL. It provides a mechanism for
implementations to store data in memory instead of on disk. By using the main-memory storage
system for volatile data such as temporary sort tables and dynamic indexes, implementations can
improve performance of many queries, such as joins.
manager
A main component of the SQL engine. The SQL engine includes several managers, including the
SQL statement manager, parser, and optimizer.
metadata
Data that details the structure of tables and indexes in the c-tree Plus. The SQL engine stores
metadata in the system catalog.
octet
A group of eight bits. Synonymous with byte, and often used in descriptions of character-set encoding
format.
ODBC application
Any program that calls ODBC functions and uses them to issue SQL statements. Many vendors have
added ODBC capabilities to their existing Windows-based tools.
ODBC data source
In ODBC terminology, a specific combination of a database system, the operating system it uses, and
any network software required to access it. Before applications can access a database through
ODBC, you use the ODBC Administrator to add a data source -- register information about the
database and an ODBC driver that can connect to it -- for that database. More than one data source
name can refer to the same database, and deleting a data source does not delete the associated
database.
ODBC driver
Vendor-supplied software that processes ODBC function calls for a specific data source. The driver
connects to the data source, translates the standard SQL statements into syntax the data source can
process, and returns data to the application. c-treeSQL includes an ODBC driver that provides access
to the c-treeSQL Server.
ODBC driver manager
www.faircom.com
All Rights Reserved
69
Chapter 4
Glossary
A Microsoft-supplied program that routes calls from an application to the appropriate ODBC driver for
a data source.
optimizer
Within the SQL engine, the manager that analyzes costs and statistics associated with the statement
and converts the relational algebra tree to the most efficient form for execution. The optimizer stores
the trees for later use.
output parameter
In a stored procedure specification, an argument in which the stored procedure returns a value after it
executes.
package
A group of related Java classes and interfaces, like a class library in C++. The Java development
environment includes many packages of classes that procedures can import. The Java runtime
system automatically imports the java.lang package. Stored procedures must explicitly import other
classes by specifying them in the IMPORT clause of a CREATE PROCEDURE statement.
parameter marker
A question mark (?) in a procedure call or SQL statement string that acts as a placeholder for an input
or output parameter supplied at runtime when the procedure executes. The CALL statement (or
corresponding ODBC or JDBC escape clause) use parameter markers to pass parameters to stored
procedures, and the SQLIStatement, SQLPStatement, and SQLCursor objects use them within
procedures.
primary key
A subset of the fields in a table, characterized by the constraint that no two records in a table may
have the same primary key value, and that no fields of the primary key may have a null value.
Primary keys are specified in a CREATE TABLE statement.
procedure body
In a stored procedure, the Java code between the BEGIN and END keywords of a CREATE
PROCEDURE statement.
procedure result set
In a stored procedure, a set of data rows returned to the calling application. The number and data
types of columns in the procedure result set are specified in the RESULT clause of the CREATE
PROCEDURE statement. The procedure can transfer data from an SQL result set to the procedure
result set or it can store data generated internally. A stored procedure can have only one procedure
result set.
procedure specification
In a CREATE PROCEDURE statement, the clauses preceding the procedure body that specify the
procedure name, any input and output parameters, any result set columns, and any Java packages to
import.
procedure variable
A Java variable declared within the body of a stored procedure, as compared to a procedure input
parameter or output parameter, which are declared outside the procedure body and are visible to the
application that calls the stored procedure.
query expression
The fundamental element in SQL syntax. Query expressions specify a result table derived from some
combination of rows from the tables or views identified in the FROM clause of the expression. Query
FairCom Corporation
Copyright 2015 FairCom Corporation
70
c-treeSQL
JDBC Developer's Guide
expressions are the basis of SELECT, CREATE VIEW, and INSERT statements, and can be used in
some expressions and search conditions.
referential integrity
The condition where the value stored in a database table’s foreign key must either be null or be equal
to some value in another table’s the matching unique or primary key. SQL provides two mechanisms
to enforce referential integrity: constraints specified as part of CREATE TABLE statements prevent
updates that violate referential integrity, and triggers specified in CREATE TRIGGER statements
execute a stored procedure to enforce referential integrity.
repertoire
The set of characters allowed in a character set.
result set
In a stored procedure, either an SQL result set or a procedure result set. More generally, another
term for result table.
result table
A virtual table of values derived from columns and rows of one or more tables that meet conditions
specified by an SQL query expression.
row identifier
Another term for tuple identifier.
search condition
The SQL syntax element that specifies a condition that is true or false about a given row or group of
rows. Query expressions and UPDATE statements can specify a search condition. The search
condition restricts the number of rows in the result table for the query expression or UPDATE
statement. Search conditions contain one or more predicates. Search conditions follow the WHERE
or HAVING keywords in SQL statements.
selectivity
The fraction of a table’s rows returned by a query.
server
Generally, in client/server systems, the part of the system that receives requests from clients and
responds with results to those requests.
snippet
In a stored procedure, the sequence of Java statements between the BEGIN and END keywords in
the CREATE PROCEDURE (or CREATE TRIGGER) statement. The Java statements become a
method in a class the SQL engine creates and submits to the Java compiler.
SQL diagnostics area
A data structure that contains information about the execution status (success, error or warning
conditions) of the most recent SQL statement. The SQL-92 standard specified the diagnostics area
as a standardized alternative to widely varying implementations of the SQLCA. c-treeSQL supports
both the SQLCA and the SQL diagnostics area. The SQL GET DIAGNOSTICS statement returns
information about the diagnostics area to an application, including the value of the SQLSTATE status
parameter.
SQL engine
The core component of the c-treeACE SQL environment. The SQL engine receives requests from
applications, processes them, and returns results. The SQL engine conveys requests to the c-tree
Plus engine.
www.faircom.com
All Rights Reserved
71
Chapter 4
Glossary
SQLCA
SQL Communications area: A data structure that contains information about the execution status
(success, error or warning conditions) of the most recent SQL statement. The SQLCA includes an
SQLCODE field. The SQLCA provides the same information as the SQL diagnostics area, but is not
compliant with the SQL-92 standard. c-treeSQL supports both the SQLCA and the SQL diagnostics
area.
SQLCODE
An integer status parameter whose value indicates the condition status returned by the most recent
SQL statement. An SQLCODE value of zero means success, a positive value means warning, and a
negative value means an error status. SQLCODE is superseded by SQLSTATE in the SQL-92
standard. Applications declare either SQLSTATE or SQLCODE, or both. SQL returns the status to
SQLSTATE or SQLCODE after execution of each SQL statement.
SQL result set
In a stored procedure, the set of data rows generated by an SQL statement (SELECT and, in some
cases, CALL).
SQLSTATE
A 5-character status parameter whose value indicates the condition status returned by the most
recent SQL statement. SQLSTATE is specified by the SQL-92 standard as a replacement for the
SQLCODE status parameter (which was part of SQL-89). SQLSTATE defines many more specific
error conditions than SQLCODE, which allows applications to implement more portable error
handling. Applications declare either SQLSTATE or SQLCODE, or both. SQL returns the status to
SQLSTATE or SQLCODE after execution of each SQL statement.
stored procedure
A snippet of Java source code embedded in an SQL CREATE PROCEDURE statement. The source
code can use all standard Java features as well as use c-treeSQL-supplied Java classes for
processing any number of SQL statements.
system catalog
Tables created by the SQL engine that store information about tables, columns, and indexes that
make up the database. The SQL engine creates and manages the system catalog.
system tables
Another term for system catalog.
tid
Another term for tuple identifier.
transaction
A group of operations whose changes can be made permanent or undone only as a unit to protect
against data corruption.
trigger
A special type of stored procedure that helps insure referential integrity for a database. Like stored
procedures, triggers also contain Java source code (embedded in a CREATE TRIGGER statement)
and use c-treeSQL Java classes. However, triggers are automatically invoked (“fired”) by certain SQL
operations (an insert, update, or delete operation) on the trigger’s target table.
trigger action time
The BEFORE or AFTER keywords in a CREATE TRIGGER statement. The trigger action time
specifies whether the actions implemented by the trigger execute before or after the triggering
INSERT, UPDATE, or DELETE statement.
FairCom Corporation
Copyright 2015 FairCom Corporation
72
c-treeSQL
JDBC Developer's Guide
trigger event
The statement that causes a trigger to execute. Trigger events can be SQL INSERT, UPDATE, or
DELETE statements that affect the table for which a trigger is defined.
triggered action
The Java code within the BEGIN END clause of a CREATE TRIGGER statement. The code
implements actions to be completed when a triggering statement specifies the target table.
tuple identifier
A unique identifier for a tuple (row) in a table. The SQL scalar function ROWID and related functions
return tuple identifiers to applications.
Unicode
A superset of the ASCII character set that uses two bytes for each character rather than ASCII's 7-bit
representation. Able to handle 65,536 character combinations instead of ASCII's 128, Unicode
includes alphabets for many of the world's languages. The first 128 codes of Unicode are identical to
ASCII, with a second-byte value of zero.
unique key
A column or columns in a table whose value (or combination of values) must be unique. Use the
UNIQUE clause of the SQL CREATE TABLE statement to create unique keys. Unique keys are also
called candidate keys.
URL
In general, a Universal Resource Locater used to specify protocols and locations of items on the
Internet. In JDBC, a database connection string in the form jdbc:subprotocol:subname. The
c-treeSQL JDBC Driver format for database URLs is jdbc:ctree:6597@host_name:db_name.
view
A virtual table that recreates the result table specified by a SELECT statement. No data is stored in a
view, but other queries can refer to it as if it were a table containing data corresponding to the result
table it specifies.
virtual table
A table of values that is not physically stored in a database, but instead derived from columns and
rows of other tables. SQL generates virtual tables in its processing of query expressions: the FROM,
WHERE, GROUP BY and HAVING clauses each generate a virtual table based on their input.
virtual machine
The Java specification for a hardware-independent and portable language environment. Java
language compilers generate code that can execute on a virtual machine. Implementations of the
Java virtual machine for specific hardware and software platforms allow the same compiled code to
execute without modification.
www.faircom.com
All Rights Reserved
73
Error messages...................................................... 66
Error Messages...................................................... 66
Index F
FairCom Typographical Conventions ....................... v
G
A
getXXX ................................................................... 55
Additional Resources ............................12, 24, 33, 45
method ............................................................... 55
An Example Connection ......................................... 51
Glossary ................................................................. 67
API, JDBC ................................................................. 1
Applet ...................................................................... 48 I
Application server ................................................... 48 Implementation in c-treeACE SQL JDBC Driver ... 52
driver files ........................................................... 49 Init .......................................................... 7, 15, 27, 35
Architecture, JDBC ................................................... 1 Internet Explorer .................................................... 47
Authentication detail ............................................... 50 Introduction ........................................................ 1, 47
Introductory Tutorial ..................................................6
B
Basic JDBC Driver Operations ............................... 47 J
Bridge drivers ............................................................ 2 JAR file ................................................................... 47
Java Archive file ..................................................... 47
C
Java URL connection string ................................... 50
Class files location .................................................. 48
Java URL Connection String ................................. 50
Class.forName ........................................................ 50
java.sql ......................................................................1
Connect to the JDBC Driver Using
JavaSoft JDK Version 1.1.3 (Windows) ................. 47
DriverManager.GetConnection ........................... 50
JavaSoft JDK Version 1.1.5 (UNIX) ....................... 47
Connecting to a database ....................................... 49
javax.sql Package .................................................. 51
Connecting to a Database ................................47, 49
JDBC .........................................................................1
Connection
applet ................................................................. 47
example .............................................................. 51
application server ............................................... 48
Connection Pooling................................................. 52
architecture ...........................................................1
Connection Pooling Support in JDBC..................... 51
class files location .............................................. 48
Connection string .................................................... 50
comparison to ODBC ............................................3
Copying JDBC Driver and Applet Class Files ........ 48
connect to a database ....................................... 49
Copying JDBC Driver Files to the Application Server
c-treeSQL JDBC driver .........................................3
(If Necessary) ..................................................... 49
driver files ........................................................... 49
Creating a Web Page That Invokes the Applet ...... 48
driver manager ......................................................1
c-treeSQL JDBC driver ............................................. 3
driver setup ........................................................ 47
D drivers ...................................................................2
Database connection environment variables ........................................ 49
example .............................................................. 51 error messages .................................................. 66
Database connectivity............................................. 49 performance ....................................................... 52
DatabaseMetaData ................................................. 56 setup .................................................................. 47
return values ....................................................... 56 type 1 driver ..........................................................2
Define .....................................................8, 16, 28, 36 type 2 driver ..........................................................3
DhJDBCApplet.class .............................................. 48 type 3 driver ..........................................................3
DhJDBCTest.jar ...................................................... 48 type 4 driver ..........................................................3
Done .....................................................11, 23, 32, 44 JDBC Architecture ....................................................1
Driver files ............................................................... 49 JDBC Compared to ODBC .......................................3
Driver Manager JDBC Conformance Notes .................................... 55
JDBC .................................................................... 1 JDBC Version Information ..................................... 53
Driver Socket SEND/RECV Timeout ...................... 53 JDBC-ODBC Bridge Drivers .....................................2
Driver, types of .......................................................... 2
L
DriverManager.GetConnection ............................... 50
Load the JDBC Driver Using Class.forName ......... 50
E
M
Environment variables ............................................ 49
Manage .................................................. 9, 19, 29, 39
www.faircom.com
All Rights Reserved
75
Managing Transactions Explicitly to Improve U
Performance ....................................................... 52 UNIX
environment variables ........................................ 49
N
URL connection string ........................................... 50
Native-Method drivers............................................... 3
User authentication detail ...................................... 50
Native-Method Drivers .............................................. 3
User Authentication Detail ..................................... 50
Native-Protocol All-Java Drivers (c-treeSQL JDBC
Using A DataSource Object To Make A Connection
Driver) ................................................................... 3
........................................................................... 51
Native-Protocol All-Java drivers (c-treeSQL) ........... 3
Netscape ................................................................. 47 V
Network-Protocol All-Java Drivers ............................ 3 Virtual machine ...................................................... 47
Network-Protocol All-Jave drivers ............................ 3
W
O Web page ............................................................... 48
Object Web Server ............................................................ 47
Properties ........................................................... 50 Windows NT
ODBC envrionment variables ........................................ 49
compared to JDBC ............................................... 3
Overview ................................................................... 1
P
Performance improvements ................................... 52
PreparedStatement.setXXX ................................... 55
Properties object ..................................................... 50
Q
Query Timeout Options .......................................... 53
Quick Tour ................................................................ 5
R
Record/Row Locking............................................... 25
Relationships .......................................................... 13
Required Java Environment ................................... 47
Required software ................................................... 47
Return values .......................................................... 56
Return Values for DatabaseMetaData Methods ..... 56
Running the Sample Application ............................ 49
S
Setting Environment Variables ............................... 49
Setting up the c-treeSQL JDBC Driver ................... 47
Setting Up the JDBC Driver
Application Server............................................... 48
Web Server ......................................................... 47
setXXX .................................................................... 55
Supported Data Types ............................................ 55
T
Transaction management ....................................... 52
Transaction Processing .......................................... 34
Type 1 JDBC driver .................................................. 2
Type 2 JDBC driver .................................................. 3
Type 3 JDBC driver .................................................. 3
Type 4 JDBC driver .................................................. 3
Types of JDBC drivers .............................................. 2
Types of JDBC Drivers ............................................. 2
FairCom Corporation
Copyright 2015 FairCom Corporation
76