getting started with java and db2 for z/os and os/390
Post on 22-Apr-2015
2.245 Views
Preview:
DESCRIPTION
TRANSCRIPT
Peggy Abelite DB2 for z/OS and OS/390 DevelopmentIBM Corporation
Getting Started with Java and DB2 for z/OS and OS/390
Web Thread
All DB2 platforms
September 3, 2002
International DB2 Users Group
Agenda
JDBCSQLJ
Java Stored ProceduresNew Java combined client
International DB2 Users Group
Example customer e-business solutions
Unix
Unix
Unix
AIX
OS/390DB2
DB2 Connect
DB2 Connect
DB2 Connect
DB2 Connect
zSeries 900
Hipersockets and hypervisor
Linux Linux Linux OS/390DB2
DB2 Connect
DB2 Connect
DB2 Connect
zSeries 900
CICS OS/390DB2
zSeries 900
WebSphere EE
IMS
A
B
C
International DB2 Users Group
JDBC driver types - defined by Java (TM)Type 1 -- implements JDBC as a layer on top of ODBC
Type 2 -- uses native method calls (JNI) to call DLLs that issue the SQL (the DLLs are specially written for JDBC)Use Type 2 for local access (and transactional remote access)
Type 3 -- network driver that is database vendor independent
Type 4 -- network driver that speaks the database's native network protocolUse Type 4 for "network" access (non-transactional)
International DB2 Users Group
JDBC Example -- Select
java.sql.PreparedStatement ps = con.prepareStatement( "SELECT ADDRESS FROM
EMP WHERE NAME=?");ps.setString(1, name);java.sql.ResultSet names = ps.executeQuery();names.next();addr =names.getString(1);names.close();
International DB2 Users Group
JDBC Examples - Call a stored procedure CallableStatement cstmt = con.prepareCall( "CALL MYRES1(?)" ); cstmt.setBigDecimal(1, startSal); boolean rsltFlag = cstmt.execute(); if ( rsltFlag ) { queryBasic = cstmt.getResultSet(); while (queryBasic.next()) { name = queryBasic.getString(1); sal = queryBasic.getBigDecimal(2,2); System.out.println( name + " " + sal ); } queryBasic.close(); }
International DB2 Users Group
SQLJ OverviewStatic SQL syntax for Java
easier than JDBC, better performance too!Wide DBMS vendor acceptance
IBM, Oracle, Sybase, Tandem...SQLJ has been accepted by ANSI for inclusion in the SQL-related standards
www.sqlj.org
International DB2 Users Group
Why use SQLJ?Static SQL performance for Java applications
significant performance advantage over JDBC
Static SQL authorization modelprovides Java with a stronger authorization model
Productivityless code written by the application programmerresulting code is easier to maintain
International DB2 Users Group
Static SQLINSERT, UPDATE, DELETE, CREATE, GRANT, etc.Singleton SELECT and cursor-based SELECTcalls to stored procedures (including result sets)COMMIT, ROLLBACKmethods for CONNECT, DISCONNECT
JDBC must be used for the dynamic SQLspecs for portable Java stored procedures
What does SQLJ support?
International DB2 Users Group
Static SQL is associated with "program"plans/packages identify "programs" to DB2program author's table privileges are usedend users are granted EXECUTE on program
Dynamic SQL is associated with "user"no notion of "program"end users must have table privileges
BIG PROBLEM FOR A LARGE ENTERPRISE!!!
Static SQL Authorization
#sql (con) { SELECT ADDRESS INTO :addr FROM EMP WHERE NAME=:name };
SQLJ:
JDBC:java.sql.PreparedStatement ps = con.prepareStatement( "SELECT ADDRESS FROM EMP WHERE NAME=?");ps.setString(1, name);java.sql.ResultSet names = ps.executeQuery();names.next();addr = names.getString(1);names.close();
-- portable across platforms and DBMSs-- compile/bind time schema checking-- static SQL performance and authorization!!!
-- concise-- strong typing
Retrieve a single row from DB2
#sql (con) {INSERT INTO T1 VALUES( :hv1, :hv2, :hv3) };SQLJ:
JDBC:CallableStatement mystmt = con.prepareCall( "INSERT INTO T1 VALUES(?,?,?)");mystmt.setString(1,hv1);mystmt.setString(2,hv2);mystmt.setInt(3,hv3);mystmt.executeUpdate();
SQLJ example: INSERT one row
What if the table has 100 cols?
International DB2 Users Group
SQLJ source
class ABC {
#sql SELECT ...
}
Java source
class ABC { call "stub" }
Extracted SQL
SELECT ... host var data
Generic SQLJtranslator
Javabytecodes
Extracted SQL
SELECT ... host var data
Javabytecodes
Extracted SQL
SELECT ... host var data
DBMS-specific"stub"
Optional step:
DBMS-specificbinder
Java Compiler
Compiling an SQLJ application
JDBC "stub" JDBC "stub"
JDBC default "stub"
JDBC V6 JDBC V7 SQLJ V6 SQLJ V70
100
200
300
400
500
600
Tra
nsac
tions
per
sec
ond
Java API Performance Comparisons
Normalized throughput for zSeries G7 with 3 engines with 100% cache hit for JDBC.SQLJ advantage increased from 20% to 35% when Java overhead was reduced.
+20%
+35%
International DB2 Users Group
Java Stored ProceduresSQLJ Part 1 specification
Output parameters are single-element arraysBecause Java doesn't allow modifying parms
Result sets are not in catalog definitionResult sets are in method signature as outputs
Because "with return" is not universalCan be JDBC, SQLJ, or both
Compiled Java on V5 and V6JAR files support in V7
International DB2 Users Group
V7: Built-in Utility Stored ProceduresAs per SQLJ specificationInvoked with CALL statement
INSTALL_JAR (file URL)Installs the Java ARchive file into the DB2 catalogJAR file contains one or more Stored Procedures
REPLACE_JARREMOVE_JAR
new JAR authorizationGRANT USAGE ON JAR
International DB2 Users Group
Tasks for OS/390 System ProgrammerSet up WLM environment, address space JCLInstall IBM S/390 JDK w/enhancementInstall JDBC/SQLJ driver
Run db2genJDBC to generate DBRMs and bind into DB2 package
-OR- use default .ser file with V7 driverSet up JAVAENV with "home" dirsProvide .profile for users
International DB2 Users Group
JAVAENV DD CARD(in WLM address space JCL)
Dataset containing RUNOPTSApplies to entire WLMENV, not individual SPs
Must set JAVA_HOMEIBM JDK 1.3.1 (persistent reusable technology)
Must set DB2_HOMEJDBC/SQLJ driver directory
Can set CLASSPATHdirectory for user classes not in JARall SP classes are shared
Limited to 245 characters
International DB2 Users Group
Language
0
200
400
600
800
1000
1200
Nor
mal
ized
Thr
ough
put -
tran
s pe
r se
cond
Java- JDBCJava - SQLJC - static
Stored Procedure Performance by Language
International DB2 Users Group
What is DB2 Common Client?
Reengineering of DB2 Connect and CAEImproved DB2 Connect and CAE consistency/performance
much higher percentage of common codeDRDA Improvements
external capabilitiesinternal performance improvements
Scrollable cursors
????
International DB2 Users Group
Objectives for new Java ClientSingle driver for Unix, Windows, and OS/390
eliminate major cause of Java porting problems
Improved Java driver integration with DB2Simplify install/deployment of Type 2 driverImprove JDBC and SQLJ performance
SQLJ is now faster than JDBC on Unix/Windows
International DB2 Users Group
DB2 Java Client Architecture
Common Code for all drivers:JDBC APIsSQLJ APIs
Type 4 DriverType 2 driver
for Unix/Windows
Type 2 driver for
OS/390 or z/OS
DRDA overTCP/IP
RRS Attach
(Any DB2 server)
Local SQL API XA Support
International DB2 Users Group
New function in new Java Client
Type 4 driver for thin clientsProvide fully compliant JDBC 2.0 driverTrace improvements
dynamically turn trace on/offmultiple levels of trace detail
Provide 100% Java application development process for SQLJ
International DB2 Users Group
OS/390DB2
Java program
Configuration D
JCC: Type 4 Driver support
Network applet driverCharacter conversion is optional
performance small download footprint
International DB2 Users Group
DB2's type 4 JDBC driverTargeted at clients that fit this profile:
prefer to not install the JDBC driver on their machinedon't need high-end performance/scalability/availability
The type 4 driver will NOT support:JTA (2--phase commit)parallel sysplex workload balancingconnection concentrator functionalitystatic SQL profilingQuery Patrollersome of the performance optimizations in the type 2 driverfull range of code page translations
If you are trying to support EJBs or high-end application servers, you should use the type 2 JDBC driver.
International DB2 Users Group
New Java API Enhancements
Scrollable cursor support Improved security for DB2 authenticationJava API for Set Client Information (SQLESETI)Improved Java SQL error informationNative DB2 server SQL error messagesConnection pooling improvements
International DB2 Users Group
Scrollable Cursor Support
Java Application
JavaDriver
DB2 Server-- Exploits DB2 engine scrolling-- Supports update operations-- Java driver performs "local" scrolling within a block of data-- minimizes network traffic
Current row
QueryResult
International DB2 Users Group
Java API for Set Client InformationFor DB2 for Unix and Windows users:
provides additional monitoring informationFor DB2 for OS/390 and z/OS users:
provides additional monitoring informationall four strings are included in all IFC records
Allows you to search accounting records or other IFC records for data related to a particular Java user or application.
the last two strings can be used for WLM prioritization of the Java connections to DDF
International DB2 Users Group
Improved SQL Error Information
DB2Diagnosable class for reporting contents of the SQLCA and SQL error message text
getSQLCode()getSQLErrmc()getSQLErrp()getSQLErrd()getSQLState()getSQLWarn()
getSQLErrorMessage() Information is accessible for both JDBC and SQLJ whenever an SQL exception is thrown
International DB2 Users Group
Native DB2 Server SQL Error Messages
"Error Message" stored procedures are provided by each DB2 server (including DB2 for OS/390 V6 and V7)Allows DB2 client to return "native" error message text for the target DB2 serverNative error message is only returned when explicitly requested
getSQLErrorMessage()
International DB2 Users Group
SQLJ Application Development Process(BIG improvements !)
100% Java application process eliminates DBRM files and .bnd files
New SQLJ serialized profile formatfully portable to all platforms -- user can deploy on any server platform without running db2profc on the target system.contains information needed for all BIND operations, without having to recustomize on each BINDmigration path for old SQLJ serialized profiles to the new format
Simplifies deployment of applications, but does require changes in existing procedures used by SQLJ users.
International DB2 Users Group
Summary
JDBC Driver TypesRemember what Type 4 is designed for
SQLJ - static SQL for a dynamic worldJava stored proceduresNew combined client for all platforms
Code portability
top related