Db2 12 for Z/OS: Application Programming Guide and Reference for Java Chapter 1
Total Page:16
File Type:pdf, Size:1020Kb
Db2 12 for z/OS Application Programming Guide and Reference for Java IBM SC27-8846-02 Notes Before using this information and the product it supports, be sure to read the general information under "Notices" at the end of this information. Subsequent editions of this PDF will not be delivered in IBM Publications Center. Always download the latest edition from Db2® 12 for z/OS® Product Documentation. 2021-07-26 edition This edition applies to Db2 12 for z/OS (product number 5650-DB2), Db2 12 for z/OS Value Unit Edition (product number 5770-AF3), and to any subsequent releases until otherwise indicated in new editions. Make sure you are using the correct edition for the level of the product. Specific changes are indicated by a vertical bar to the left of a change. A vertical bar to the left of a figure caption indicates that the figure has changed. Editorial changes that have no technical significance are not noted. © Copyright International Business Machines Corporation 1998, 2017. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents About this information.......................................................................................... xi Who should read this information...............................................................................................................xi Db2 Utilities Suite for z/OS..........................................................................................................................xi Terminology and citations........................................................................................................................... xi Accessibility features for Db2 12 for z/OS.................................................................................................xii How to send your comments..................................................................................................................... xii How to read syntax diagrams....................................................................................................................xiii Chapter 1. Java application development for IBM data servers............................... 1 Chapter 2. Supported drivers for JDBC and SQLJ....................................................3 JDBC driver and database version compatibility........................................................................................ 4 How to find the IBM Data Server Driver for JDBC and SQLJ version..........................................................5 Db2 for z/OS and IBM Data Server Driver for JDBC and SQLJ levels......................................................... 5 Db2 on Linux, UNIX, and Windows systems and IBM Data Server Driver for JDBC and SQLJ levels........7 Chapter 3. JDBC application programming............................................................. 9 Example of a simple JDBC application........................................................................................................9 How JDBC applications connect to a data source.................................................................................... 11 Connecting to a data source using the DriverManager interface with the IBM Data Server Driver for JDBC and SQLJ................................................................................................................13 Connecting to a data source using the DataSource interface.............................................................20 How to determine which type of IBM Data Server Driver for JDBC and SQLJ connectivity to use....22 JDBC connection objects..................................................................................................................... 23 Creating and deploying DataSource objects........................................................................................23 Java packages for JDBC support...............................................................................................................25 Learning about a data source using DatabaseMetaData methods...........................................................25 DatabaseMetaData methods for identifying the type of data server..................................................26 Using DatabaseMetaData extensions to identify the Db2 Connect version and the IBM Data Server Driver for JDBC and SQLJ version....................................................................................... 28 Variables in JDBC applications..................................................................................................................28 Comments in a JDBC application.............................................................................................................. 29 JDBC interfaces for executing SQL............................................................................................................30 Creating and modifying database objects using the Statement.executeUpdate method................. 30 Updating data in tables using the PreparedStatement.executeUpdate method............................... 31 JDBC executeUpdate methods against a Db2 for z/OS server........................................................... 33 Making batch updates in JDBC applications....................................................................................... 33 Learning about parameters in a PreparedStatement using ParameterMetaData methods...............37 Data retrieval in JDBC applications..................................................................................................... 38 Calling stored procedures in JDBC applications................................................................................. 51 LOBs in JDBC applications with the IBM Data Server Driver for JDBC and SQLJ...............................56 ROWIDs in JDBC with the IBM Data Server Driver for JDBC and SQLJ.............................................. 61 Update and retrieval of timestamps with time zone information in JDBC applications.................... 63 Distinct types in JDBC applications..................................................................................................... 70 Invocation of stored procedures with ARRAY parameters in JDBC applications...............................70 Savepoints in JDBC applications......................................................................................................... 71 Retrieval of automatically generated keys in JDBC applications........................................................73 Named parameter markers in JDBC applications............................................................................... 76 Retrieving JSON documents from a ResultSet....................................................................................79 iii Providing extended client information to the data source with IBM Data Server Driver for JDBC and SQLJ-only methods..................................................................................................................82 Providing extended client information to the data source with client info properties.......................83 Extended parameter information with the IBM Data Server Driver for JDBC and SQLJ......................... 86 Using DB2PreparedStatement methods or constants to provide extended parameter information...................................................................................................................................... 87 Using DB2ResultSet methods or DB2PreparedStatement constants to provide extended parameter information....................................................................................................................89 XML data in JDBC applications..................................................................................................................90 XML column updates in JDBC applications......................................................................................... 91 XML data retrieval in JDBC applications..............................................................................................93 Invocation of routines with XML parameters in Java applications..................................................... 96 Binary XML format in Java applications...............................................................................................97 Java support for XML schema registration and removal.....................................................................99 Bidirectional (BiDi) text layout transformation.......................................................................................100 Inserting data from file reference variables into tables in JDBC applications...................................... 102 Loading a Db2 for z/OS table by using an IBM Data Server Driver for JDBC and SQLJ method........... 105 Transaction control in JDBC applications............................................................................................... 106 IBM Data Server Driver for JDBC and SQLJ isolation levels............................................................. 106 Committing or rolling back JDBC transactions..................................................................................107 Default JDBC autocommit modes..................................................................................................... 107 Exceptions and warnings under the IBM Data Server Driver for JDBC and SQLJ..................................108 Handling an SQLException under