IBM Data Server Driver for JDBC and SQLJ for IDS
Total Page:16
File Type:pdf, Size:1020Kb
IBM Informix Version 3.58 IBM Data Server Driver for JDBC and SQLJ for IDS SC23-8619-00 IBM Informix Version 3.58 IBM Data Server Driver for JDBC and SQLJ for IDS SC23-8619-00 Note Before using this information and the product it supports, read the information in “Notices” on page B-1. This document contains proprietary information of IBM. It is provided under a license agreement and is protected by copyright law. The information contained in this publication does not include any product warranties, and any statements provided in this manual should not be interpreted as such. When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © Copyright International Business Machines Corporation 2007, 2009. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Introduction ..................................ix In This Introduction.................................ix About This Publication................................ix Types of Users .................................ix Assumptions About Your Locale ...........................ix What’s New for IBM Data Server Driver for JDBC and SQLJ for IDS ................ix Documentation Conventions .............................xv Technical Changes ................................xv Feature, Product, and Platform Markup .........................xv Example Code Conventions.............................xvi Additional Documentation ..............................xvi Compliance with Industry Standards ..........................xvi Syntax Diagrams .................................xvii How to Read a Command-Line Syntax Diagram .....................xviii Keywords and Punctuation .............................xix Identifiers and Names ..............................xix How to Provide Documentation Feedback .........................xx Chapter 1. Java application development for IBM data servers ...........1-1 Chapter 2. Supported drivers for JDBC and SQLJ .................2-1 Chapter 3. IBM Data Server Driver for JDBC and SQLJ restrictions for IDS ......3-1 Chapter 4. Installing the IBM Data Server Driver for JDBC and SQLJ.........4-1 Customization of IBM Data Server Driver for JDBC and SQLJ configuration properties ..........4-2 Chapter 5. JDBC application programming ....................5-1 Example of a simple JDBC application ..........................5-1 How JDBC applications connect to a data source ......................5-3 Connecting to a data source using the DriverManager interface with the IBM Data Server Driver for JDBC and SQLJ ....................................5-4 Connecting to a data source using the DataSource interface ..................5-7 JDBC connection objects ..............................5-9 Creating and deploying DataSource objects .......................5-9 Java packages for JDBC support ............................5-10 Learning about a data source using DatabaseMetaData methods .................5-11 DatabaseMetaData methods for identifying the type of data source ...............5-12 Variables in JDBC applications ............................5-13 JDBC interfaces for executing SQL ...........................5-13 Creating and modifying database objects using the Statement.executeUpdate method .........5-14 Updating data in tables using the PreparedStatement.executeUpdate method ............5-15 Making batch updates in JDBC applications .......................5-16 Learning about parameters in a PreparedStatement using ParameterMetaData methods ........5-19 Data retrieval in JDBC applications ..........................5-20 Calling stored procedures in JDBC applications ......................5-30 LOBs in JDBC applications with the IBM Data Server Driver for JDBC and SQLJ ..........5-31 ROWIDs in JDBC with the IBM Data Server Driver for JDBC and SQLJ..............5-37 Savepoints in JDBC applications ...........................5-38 Retrieving automatically generated keys in JDBC applications .................5-39 || Using named parameter markers in JDBC applications ...................5-42 Providing extended client information to the data source with client info properties .........5-45 Transaction control in JDBC applications .........................5-49 IBM Data Server Driver for JDBC and SQLJ isolation levels..................5-49 © Copyright IBM Corp. 2007, 2009 iii Committing or rolling back JDBC transactions ......................5-49 Default JDBC autocommit modes ..........................5-50 Exceptions and warnings under the IBM Data Server Driver for JDBC and SQLJ ...........5-50 Handling an SQLException under the IBM Data Server Driver for JDBC and SQLJ ..........5-52 Handling an SQLWarning under the IBM Data Server Driver for JDBC and SQLJ ..........5-56 Retrieving information from a BatchUpdateException....................5-57 Disconnecting from data sources in JDBC applications ....................5-59 Chapter 6. SQLJ application programming ....................6-1 Example of a simple SQLJ application ..........................6-1 Connecting to a data source using SQLJ .........................6-3 SQLJ connection technique 1: JDBC DriverManager interface .................6-3 SQLJ connection technique 2: JDBC DriverManager interface .................6-5 SQLJ connection technique 3: JDBC DataSource interface ...................6-6 SQLJ connection technique 4: JDBC DataSource interface ...................6-7 SQLJ connection technique 5: Use a previously created connection context .............6-8 Java packages for SQLJ support ............................6-9 Variables in SQLJ applications .............................6-9 Comments in an SQLJ application ...........................6-11 SQL statement execution in SQLJ applications .......................6-11 Creating and modifying IDS objects in an SQLJ application ..................6-11 Performing positioned UPDATE and DELETE operations in an SQLJ application ..........6-12 Data retrieval in SQLJ applications ..........................6-18 Calling stored procedures in SQLJ applications ......................6-28 LOBs in SQLJ applications with the IBM Data Server Driver for JDBC and SQLJ...........6-28 SQLJ and JDBC in the same application ........................6-30 Controlling the execution of SQL statements in SQLJ ....................6-33 ROWIDs in SQLJ with the IBM Data Server Driver for JDBC and SQLJ ..............6-34 Savepoints in SQLJ applications ...........................6-36 SQLJ utilization of SDK for Java Version 5 function .....................6-36 Transaction control in SQLJ applications .........................6-39 Setting the isolation level for an SQLJ transaction .....................6-39 Committing or rolling back SQLJ transactions ......................6-40 Handling SQL errors and warnings in SQLJ applications ...................6-40 Handling SQL errors in an SQLJ application .......................6-40 Handling SQL warnings in an SQLJ application .....................6-41 Closing the connection to a data source in an SQLJ application .................6-41 Chapter 7. Preparing and running JDBC and SQLJ programs ............7-1 Program preparation for JDBC programs .........................7-1 Program preparation for SQLJ programs .........................7-1 Running JDBC and SQLJ programs ...........................7-1 Chapter 8. Security under the IBM Data Server Driver for JDBC and SQLJ ......8-1 User ID and password security under the IBM Data Server Driver for JDBC and SQLJ ..........8-2 User ID-only security under the IBM Data Server Driver for JDBC and SQLJ .............8-4 Encrypted password, user ID, or user ID and password security under the IBM Data Server Driver for JDBC and SQLJ .....................................8-5 IBM Data Server Driver for JDBC and SQLJ support for SSL...................8-6 Configuring connections under the IBM Data Server Driver for JDBC and SQLJ to use SSL .......8-6 Configuring the Java Runtime Environment to use SSL ...................8-7 Chapter 9. Problem diagnosis with the IBM Data Server Driver for JDBC and SQLJ . 9-1 Example of using configuration properties to start a JDBC trace .................9-2 Example of a trace program under the IBM Data Server Driver for JDBC and SQLJ ...........9-3 Techniques for monitoring IBM Data Server Driver for JDBC and SQLJ Sysplex support .........9-6 Chapter 10. System monitoring for the IBM Data Server Driver for JDBC and SQLJ 10-1 IBM Data Server Driver for JDBC and SQLJ remote trace controller ................10-3 Enabling the remote trace controller .........................10-3 iv IBM Data Server Driver for JDBC and SQLJ for IDS Accessing the remote trace controller .........................10-4 Chapter 11. Java client support for high availability on IBM data servers ......11-1 Java client support for high availability for connections to DB2 Database for Linux, UNIX, and Windows servers 11-2 Configuration of DB2 Database for Linux, UNIX, and Windows high availability support for Java clients . 11-2 Example of enabling DB2 Database for Linux, UNIX, and Windows high availability support in Java applications..................................11-5 Operation of automatic client reroute for connections to DB2 Database for Linux, UNIX, and Windows from Java clients ..................................11-5 Java application programming requirements for high availability for connections to DB2 Database for Linux, UNIX, and Windows