db2 udb and java: fast, - haaga-helia...

56

Upload: others

Post on 16-Mar-2020

22 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and
Page 2: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

2

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application DevelopmentBy Gwyneth Evans

Abstract Developing and deployingJava applications that access data from one or more databases doesn’t require the skills of a superhero. Choosing the right database for your Java application can make application development fast and easy—and give you the peace of mind that your application will be stable and perform well. This article shows you what makes IBM® DB2® Universal Database for Linux®, UNIX®, and Windows® (DB2 UDB) the database of choice for Java developers.

Page 3: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

3

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

IntroductionYou might have viewed the database in a solution as just a black box for data input and retrieval. After all, database administrators usually worry about “the box.” However, the success of an application is increasingly determined by the choice of database used. The database has to make it fast and easy for application developers to create applications for it. So Java developers are starting to have a greater say about which database supports their applications.

Given a choice, Java developers consistently choose DB2 Universal Database for Linux, UNIX, and Windows (DB2 UDB). Why? Because of the reliability, availability, scalability, and performance of DB2 UDB as well as the excellent IBM tooling available for working with tables, SQL statements, stored procedures, and triggers. These tools are now seamlessly integrated into IBM Rational Application Developer Version 6.0, a decidedly user-friendly Java integrated development environment (IDE) based on the Eclipse framework. Rational Application Developer also integrates tooling for working with DB2 UDB, Web Sphere and Rational products as well as other products. This means that with one IDE you can work with a variety of databases, develop, test, and deploy Java applications, as well as manage application servers and source code.

With a reliable database and integrated application development tooling support from the design to deployment stage in a single environment, you can harness the power of DB2 UDB, develop a wide range of Java applications, and increase developer productivity and satisfaction.

Page 4: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

4

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

This eBook explores some of the factors that from a Java developer’s perspective make DB2 UDB the right database choice for Java database application development.

The IBM commitment to the Java developer communityIBM and the Java developer community have a strong partnership founded on making Java application development easier. IBM has regularly participated in the Sun Open Process to drive new technologies into the Java standard and has invested over $50 million in a variety of open-

source technologies, including the Eclipse Platform – a Java development framework that supports the integration of other developer tools. IBM released the Eclipse framework to the open-source community is developing its own products on this framework, many of which directly benefit Java developers.

To support small-scale Java application development, IBM donated to the open source community IBM Cloudscape which is also known as Apache Derby: a free, 100% DB2 UDB SQL-compliant database that can be embedded in application solutions. To work with Apache Derby and Cloudscape databases, IBM provides an Eclipse-based set of tools called IBM Web Tools. When a more full-feature database is needed to support increasingly more complex applications and larger

Page 5: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

5

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

volumes of data, developers can upgrade to DB2 UDB and Rational Application Developer. Rational Application Developer not only contains tooling to support the full life cycle of Java application development but is also easy to adopt. As an Eclipse-based tool, Rational Application Developer has the same look and feel and features of IBM Web Tools, plus a lot more functionality. So if you are starting out small, start with the free Cloudscape database and application development tools. As your Java database application development skills and needs grow, the open-source community and IBM will be there to support your product and tooling needs with solutions that you can trust based on open standards.

If your database applications have grown beyond the basic, or if they never were basic to begin with, then you need a robust, enterprise-level database for which you can quickly and easily develop applications. In other words, you need DB2 UDB.

DB2 UDB has an established reputation for reliabilityIn an On Demand system with a Web server with an e-commerce engine or an online service, the entire system, including the database, must be very robust. The current expectation is that these systems maintain 24 x 7 up times. Changes to your business needs or customer base mean that you must be able to provision your system’s resources easily. And database performance cannot be a bottleneck for your application performance. In short, you must be able to trust that the database supporting your applications will allow the system to run successfully under various conditions.

Page 6: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

6

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Applications remain highly available How long is an online shopper going to wait for a database server to get back online after an outage to complete an order? It depends, but it’s pretty likely that a shopper will abandon the order and move on to the next online store that sells similar products at similar prices.

The opportunity cost of a database outage can mean much more than lost sales. Database outages can result in workers sitting idle because they can’t do their work, the halting of a production line or order delivery system, or incomplete or incorrect financial transactions. Loss of productivity, reduced customer satisfaction and the risk of liability due to incorrect data are just a few reasons why database downtime costs can be devastatingly huge. There is just no excuse for applications being unavailable because a database server went down. What database can you trust to run your applications successfully under varied conditions?

Page 7: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

7

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

In shops that have very high cost-per-minute downtimes, you will find DB2 UDB databases. Traditionally, these have been mainframe-based systems, but more and more organizations now use Linux, UNIX, and Windows operating systems. More than 80 percent of Fortune 500 customers use DB2 UDB,

while 100 percent of Fortune 100 companies use DB2 UDB or a DB2 UDB family product. Why? In today’s 24x7 “serve them quickly or lose them” e-commerce paradigm, the proven robustness of DB2 is of critical importance.

Several top fortune 500 companies have been running DB2 UDB for upwards of 8 years. Many of these customers have not experienced unscheduled downtime caused by a database outage and a few have maintained 99.98% application availability. Planning for IT outages is a necessity and with the new DB2 UDB High Availability and Disaster Recovery (HADR) feature, DB2 UDB system failover and recovery can take as little as 15 seconds such that critical applications remain available. For more on

Applications scale well under different database workloadsAlthough the user demand on IT systems is typically predictable and can be planned for well in advance, your Web site traffic might increase unexpectedly – perhaps because of a BBC

Page 8: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

8

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

news flash, a competitor’s outage, or a comment on a popular newsgroup. When such a sudden spike in activity occurs, your database workload can shoot up from a few hundred transactions per minute to ten thousand of them (a 100-fold increase) in a few minutes. DB2 UDB can accommodate this kind of unpredictable growth with little effort. Whether your user demand is predictable or unpredictable, DB2 UDB can handle it stably.

Scalability also means the ability to grow or shrink your system easily. Because DB2 UDB runs on many popular platforms--including parallel UNIX, Linux, and Windows operating systems--a DB2 UDB database can scale from a workstation-based system to a UNIX box to a Sysplex of mainframes, if

required. Although rehosting a database requires a considerable amount of work, most of the time the data throughput scales without any change to your applications.

Applications perform at top speed due to superior Optimizer and JDBC driver technologyDatabase performance is at the core of application performance. The last thing you want after deploying your applications is to discover that the database or the APIs that

Page 9: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

9

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

access the database are not efficient and become a performance bottleneck.

DB2 UDB is a performance benchmark industry leader that consistently ranks as a top database choice for both OLTP and BI-based applications. DB2 UDB has recently scored yet another record Java benchmark result with the SPECjAppServer 2004 benchmark. This benchmark tests how efficiently a Java database client application performs a series of common queries. In this benchmark, DB2 UDB

scored an amazing 1343.47 jops/sec (jAppServer operations per second). In the last 12 months, no other database vendor has even come close to challenging this record score. DB2 UDB has been the industry leader in Java Database Technology since the beginning of the Java Benchmarking era.

For top performance, you need an industry-proven database engine that rewrites and optimizes queries for performance and provides the fastest possible data access plans for every query. DB2 UDB performance is further enhanced by fast JDBC driver performance that supports a choice of static or dynamic SQL API access. With database support for features such as

Page 10: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

10

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

stored procedures, generated columns, and triggers, you can program logic within the database and thus benefit from an additional performance boost with the assurance that you have created the best possible application performance.

IBM’s regular investment in research and development in database optimizer, feature, and performance technologies ensures top database performance. For more details about Java and DB2 UDB performance, refer to http://www.spec.org/jAppServer2004/results/jAppServer2004.html.

Integration challenges are simplifiedIncreasingly, IT solutions require flexibility and the ability to integrate information and applications. The IBM commitment to open standards and integration means that you won’t be locked in ever to using just one operating system or even one database. DB2 UDB runs on more platforms and operating systems than any other database on the market. DB2 UDB supports a choice of integrated development environments including Rational, Web Sphere Studio, Eclipse, and Microsoft Visual Studio .NET. As your business grows through mergers and acquisitions, or your customers move to new technologies, DB2 UDB and Java can flexibly support your hardware, operating system, and application requirements all the way.

Java’s greatest feature is its portability, so why expect anything less from your database or database drivers?

Page 11: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

11

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

DB2 UDB provides extensive database support for JavaEverybody likes choice. Choice means flexibility. When it comes to picking an application programming interface (API) for your applications to use for connecting to and working with DB2 UDB databases, the IBM DB2 Universal JDBC Driver provides you with two options: Java Database Connectivity (JDBC) and SQL Java (SQLJ).

DB2 Universal JDBC Driver provides unparalleled JDBC supportJDBC technology is the de facto standard for accessing data from DB2 UDB and other modern relational database systems using dynamic SQL in Java applications. JDBC support, which is included in the Java 2 Platform, Standard Edition (J2SE) release, is implemented using a JDBC driver, a set of Java classes, and APIs that support using SQL within a Java application. Many JDBC drivers provide basic JDBC support, but only a few--such as the DB2 Universal JDBC Driver--provide extensive JDBC functionality.

The DB2 Universal JDBC Driver has a purely Java implementation that includes both JDBC type 2 and type 4 connectivity support within a single driver that can be used to connect to DB2 UDB for Linux, UNIX and Windows, DB2 UDB for z/OS, DB2 UDB for iSeries, Apache Derby, and Cloudscape databases. The common SQL API compilation allows you to develop applications in Linux environments that you can later successfully re-build and deploy on z/OS environments.

Page 12: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

12

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Combined Type 2 and Type 4 connectivity support makes the driver not only portable, but also secure, and independent of driver-type connectivity. An application loads a single driver instance for type 2 and type 4 JDBC driver implementations. The application can then make connections (concurrently, if needed) for both types of connectivity using this single driver instance. Java console or desktop applications on a client computer are well served by JDBC type 2 support, however type 2 connectivity does not support Java applets. Applets and a wide range of Java client and server applications require JDBC type 4 connectivity driver support.

In addition, the DB2 Universal JDBC Driver provides full JDBC 3.0 API functionality, and its type 2 connectivity support adheres to the current J2EE certification standard. This driver is by far the best, most portable, high performance DB2 UDB JDBC driver available.

A less well known feature of this driver is that it also supports static SQL execution through an additional API, an extension of JDBC really, called SQLJ. This API provides static SQL support should you want to use static SQL for performance, security, code management, or other reasons. The DB2 Universal JDBC Driver is the only JDBC driver to provide support for static SQL – a unique and very nice option to have.

JDBC and SQLJ provide dynamic and static SQL support optionsJava applications that use JDBC APIs do not require pre-compilation, a process by which the SQL statements within an application are compiled separately prior to application run-

Page 13: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

13

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

time. Instead, JDBC generally makes use of dynamic SQL in which SQL statements are prepared and executed at application run-time. This is particularly useful if you have a program that builds queries in real-time or that have an interactive query component. These dynamic queries get an extra performance boost from DB2 UDB thanks to SQL statement caching which improves the execution time of statements that are repeatedly used that execute in a very short time. The efficient re-use of a dynamically prepared access plan over and over, reduces total dynamic preparation times for applications.

Since most Java developers program applications that use dynamic SQL, it is sometimes hard to imagine any other way, but performance requirements are slowly making Java developers look towards the static SQL support of SQLJ. SQLJ is a newer, but increasingly well-received interface that adheres to the ANSI standard and to the J2SE specification). It is really an extension of JDBC that provides a convention for embedding SQL statements in Java using a simple, easy to use high level syntax. Embedded SQL statements are said to be “static” because they are textually evident in the Java program, and can therefore be prepared when the containing Java program is translated (compiled). This can result in much faster application performance, because the overhead of compiling the SQL statements is done once at pre-compilation time instead of each time the SQL statement is executed. SQLJ can be more efficient than JDBC, especially for infrequently called SQL with very short execution time. If it takes some 20-50 milliseconds to prepare an SQL call, and if the SQL statement

Page 14: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

14

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

executes in 20-50 milliseconds, then you have 100 percent overhead with JDBC which you wouldn’t have with SQLJ.

The DB2 UDB SQLJ API is unique in its support of static SQL statements in Java, and in its ability to provide controlled database access at the DB2 UDB package level instead of only at the application level.

In the earliest days of the SQLJ API, applications written using it could only contain static SQL. Since most Java developers had a greater need for dynamic SQL over static SQL, the general preference was to use the JDBC API, but SQLJ now supports the use of traditional JDBC methods alongside SQLJ static SQL methods. This means that with SQLJ developers can implement the best of static and dynamic SQL support in their applications with a single API. Talk about having your cake and eating it too!

JDBC and SQLJ: A look at the source codeFigures 1 and 2 show examples of source code respectively written in JDBC and SQLJ. The source code establishes a connection to a DB2 UDB database named MYDB, executes a query, retrieves the result and stores it in a variable and then executes a second query.

Page 15: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

15

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 1: Java code using JDBC API dynamic SQL methods to connect to and query a database

Page 16: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

16

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 2: Java code using SQLJ API static SQL methods to connect to and query a database

Figure 1 and Figure 2 demonstrate how to code a simple database connection, modify, and query tables in each of JDBC and SQLJ. For more complex queries, somewhat less code is required to access column values due to the use of host variables which eliminate the need for space consuming ResultSet method calls. For more complex queries that retrieve

Page 17: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

17

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

more column values and that reference parameter markers, SQLJ can often requires as little as 1/7th the code that JDBC does. This can make it faster to develop with and debug and additionally make your code more readable.

Comparison of JDBC and SQLJ APIsThere are other factors to consider when choosing between using the JDBC or SQLJ API. Some of these factors are outlined in the following table:

Page 18: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

18

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Page 19: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

19

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Table 1: Comparison of SQLJ and JDBC

Which API should you use? Often the choice of which API to use comes down to what feature you can not do without. For example: JDBC is the only API option for you if you

Page 20: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

20

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

want to execute dynamic SQL which might be required in a program that builds queries on-the-fly or has an interactive component. However if the need for performance outweighs the time required to learn a new API, then SQLJ has many nice properties that will serve you well. If you are in doubt as to which API to choose, the current best practice for DB2 UDB for Linux, UNIX, and Windows is to use JDBC.

DB2 has been praised by the database industry and community for having the best SQLJ runtime support and tooling in the market. With more tooling support for SQLJ emerging from IBM included in Rational Application Developer, attention is switching to SQLJ and its adoption rate is steadily increasing.

Regardless which API you choose to use now, the good news is that all the support that you need for both JDBC and SQLJ API support is in one driver: the DB2 Universal JDBC driver.

DB2 supports JDBC, SQLJ, and SQL stored procedures and user-defined functionsDB2 supports the creation of powerful stored procedures and SQL language extensions, known as user defined functions in Java that can be multi-threaded and thread safe. Stored procedures can be used to minimize network traffic between client applications and database servers by offloading database related business logic to the server. User-defined functions provide a means for extending the functionality of the SQL language. Both of these types of routines can be created in Java and other programming language.

Page 21: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

21

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

In DB2 UDB Java stored procedures are database objects that are created in the database using the CREATE PROCEDURE statement. Java based UDFs are created using the CREATE FUNCTION statement. These statements associate the procedure or function object with a Java class that is loaded and run when the object is invoked. User-defined function can be invoked within an SQL statement. Stored procedures can be invoked using the CALL statement from anywhere that statement is supported. This includes applications, other stored procedures (implemented in any supported programming language and running on any platform), and triggers. Calling stored procedures from triggers allows you to directly associate logic with events (insert, update, and delete operations) on database tables that map to logical events (for example the modification or removal of an inventory item) without having to poll for changes in table data.

Page 22: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

22

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 3: Reduced client-server network traffic when applications use stored procedures

In DB2 UDB Version 8 when Java stored procedures and user defined functions are created, they can be specified to be either THREADSAFE or NOT THREADSAFE. The THREADSAFE option indicates that the routine is thread safe in which case DB2 UDB uses only a single JVM (Java Virtual Machine) on the DB2 UDB Server for multiple instances of the routine invocation. With this as the default option in DB2 UDB Version 8, less memory is required for concurrent Java stored procedure invocations and therefore Java routines perform better than ever!

Page 23: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

23

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 4: Stored procedures within Java application architecture

SQL procedures provide another implementation option if you prefer to implement your procedure logic in the higher level language of SQL.

They can be implemented in SQL making use of DB2 UDB’s native SQL Procedural Language (SQL PL) which provides an easy to use SQL syntax for implementing control flow logic around traditional SQL statements, or in other programming languages including Java that makes use of either the JDBC or SQLJ interfaces. Like procedures in any programming language, they can accept one or more input parameters and return one or more output parameters. They can contain and execute an extensive range of SQL statements, call stored

Page 24: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

24

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

procedures written in a different supported programming languages, and return one or more result sets to the caller.

DB2 supports the J2EE specificationIf you code to the Java 2 Platform Enterprise Edition (J2EE) 1.4 standard, the advanced query optimization feature of DB2 UDB will ensure fast data access for your application. To also ensure fast application development times, IBM Rational Application Developer makes an ideal development environment.

To understand how the J2EE specification affects interactions with databases, it is first important to understand the goal of the specification to provide standardized interfaces.

The J2EE specification defines a standard for programming that makes interoperability of application components that contain common business logic possible across and between enterprise systems. It specifies a standard architecture and API that defines how an application server and its logical sub-components are to be designed and implemented. With this model developers are able to define reusable segments of code that can be combined to create new applications. This component model approach reduces development time, allows for testing automation, improved class object reuse, and better manageability of class objects.

Page 25: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

25

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 5: J2EE Application Mode

A key ingredient in this implementation is Enterprise JavaBeans (EJBs). EJBs are server-based components designed to implement business logic of applications for use by applications across an enterprise. They are scalable in that they can be deployed to multiple servers across an enterprise and can be invoked by client applications that exist on multiple platforms too. EJBs run in a container on an application server. A container is vendor supplied code that follows the J2EE specification, manages instances of EJBs, and provides for the system-level services required to support the EJBs.

Three types of EJBs are specified: Session Beans, Message Driven Beans, and Entity Beans. Message driven beans are used to implement logic related to communication between other beans and clients. Session beans are used to define logic

Page 26: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

26

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

that might relate to user interaction or interaction between other beans as well as transaction control. Entity beans are used to represent, retrieve and update data objects, or collections of data objects. Entity beans directly interact with the database and are of great interest to Java database application developers.

Because the goal of EJBs is to provide standardized interfaces, much of the Java code required to implement them can be done automatically by tools that support J2EE development (such as IBM Rational Application Developer). The SQL to access and update the data is generated as part of the entity bean to abstract the interaction with the data. As a Java developer, you can focus on writing code that interacts with the entity bean API that is more generic, and allow the entity bean to mange the SQL required to interact with the database.

Figure 6: Role of entity beans in the J2EE architecture

Page 27: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

27

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

This means that you no longer have to code SQLJ or JDBC API calls and that you no longer have to be an expert in SQL, which means you are free to focus on mastering other parts of the J2EE model. Like switching from driving a standard car to an automatic: it is easier and less skill is required, but you give up fine control over how data is accessed and therefore performance.

Retrieval of and updates to data are implemented through the use of standard EJB object get and set methods, however there is also a provision for implementing queries in J2EE. The J2EE specification defines an EJB Query Language (EJB QL) that can be used to implement more complex query-like methods for entity beans. EJB QL uses the abstract persistence schema of the entity bean as a data model and is not tied to a specific database implementation. The idea of EJB QL is to provide a way to specify a query which depends, not on a particular set of underlying database tables, but rather only on the EJB and the relationships that exist between them. Thus traditional query parameter markers in the EJB model would map to parameters in an EJB method that implements the query like logic. Although EJB QL is like SQL, and actually compiles down to SQL at compile time, J2EE provides a distinct abstraction from traditional API and SQL use and represents a departure from the Java developer’s role as both an implementer of Java and SQL.

There is some controversy over this in the marketplace, but most J2EE developers have decided that the better application

Page 28: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

28

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

server management benefits outweigh the partial loss of database access control. The soon forthcoming J2EE EJB 3.0 specification promises to address this point; however there is good news for those using DB2 UDB databases.

The good news is that, behind the scenes, regardless of the SQL that is generated to access the database, DB2 UDB can optimize whatever SQL it is given and execute that SQL with the best possible performance. The DB2 UDB optimizer is a key component of the database engine. Queries are parsed and rewritten in the database engine and the fastest possible data access plans are generated so that developers can trust that DB2 UDB will get the data, the fastest way possible every time.

It doesn’t matter if a Java developer chooses to write to the J2SE or J2EE standard, DB2 UDB’s advanced technology will make sure to support Java applications with the most reliable and fastest data access.

To implement a J2EE infrastructure you require:

• An application server such as IBM’s Websphere Application Server that implements the J2EE standard to support 1st and 2nd tier application management needs.

• A database such as DB2 UDB or Apache Derby/IBM Cloudscape to support your 3rd tier pervasive data management needs

• A JDBC 3.0 compliant driver such as the IBM DB2 Universal JDBC Driver to access database management systems from various Java based program modules that can

Page 29: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

29

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

exist on client workstations or within application servers. • A Java Development Kit (JDK) 1.4 environment so that you

can access the new JDBC 3.0 programming interfaces J2EE requires

Once you have the infrastructure, to develop J2EE components and applications you will probably also want a development tool with good support and documentation to help your developers build and maintain EJBs. The ideal tool should also help you manage J2EE, web, database, and application components, the application server, provide a test environment for your EJBs, provide source control support, and tooling for interacting with your database objects. The ideal choice in the market right now delivers all of this: IBM Rational Application Developer

IBM Rational Application Developer is part of the IBM integrated software product stack that makes developing database applications fast and easy. Fast, easy Java database application developmentThanks to the extensive tooling both within DB2 UDB and integrated into related IBM products, you can develop Java applications that access DB2 UDB databases quickly and easily. You get tooling where you need it, when you need it.

Rational Application Developer – an integrated desktop with DB2 UDB toolingIf your database application development needs extend beyond forming SQL statements or the odd stored procedure, to work efficiently, you probably would like database tooling available

Page 30: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

30

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

right within your core Java IDE. IBM provides a fully integrated Java development environment that comes complete with a full-suite of database and SQL specific tooling: IBM Rational Application Developer.

Rational Application Developer provides easy-to-use tooling for doing just about every step in the Java application development process. Quickly design, develop, analyze, test, profile, assemble, and deploy Web, Web services, Java, J2EE, and portal applications with this comprehensive, integrated development environment (IDE). The IDE is optimized for DB2 UDB and WebSphere software so that you can work with your databases, database objects, application servers, and more from within one IDE. This IDE:

• Supports advanced J2EE development--including Enterprise JavaBean (EJB) components--portal, and UML-based development

• Contains IBM Rational ClearCase® LT for source code version control

• Provides tools for building JavaServer Pages (JSP) and servlet-based Web applications, Java applications, and Web services

• Provides for visual development with JavaServer Faces components and Enterprise Generation Language (EGL) for generating Java code

• Includes tooling for managing database connections, creating database objects, creating and testing stored procedures and user-defined functions, generating SQL, and performing the important relational mappings required for developing J2EE

Page 31: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

31

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

entity beans.• Contains integration into and facilities for report generation

using Business Object’s Crystal Reports• And more…

Now that is a powerful tool!

By providing you with tools that automate many tedious steps and a central interface for working with related products (such as DB2 UDB and WebSphere Application Server), Rational Application Developer can significantly boost your productivity.

Eclipse base of Rational Application Developer allows you to extend the IDERational Application Developer is powered by the open source Eclipse 3.0 Platform, a Java-based, extensible development platform for tools integration. The plug-in-based Eclipse framework makes it easy for your team to create, integrate, and use software tools that support multiple languages, platforms, and vendors.

Rational Application Developer provides a comprehensive application development environment for creating and maintaining J2SE, J2ME, and J2EE-compliant enterprise application systems. Because Rational Application Developer is built on the Eclipse Platform, your development team can adapt and extend their development environment with best-of-breed plug-ins from IBM and the Eclipse community to match your needs and maximize your productivity through the many features it provides:

Page 32: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

32

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

• Perspectives give you focused views of project subcomponents

Rational Application Developer provides you with a series

of perspectives that selectively offer you various tools based on your role in a development team, your project, or the task at hand. All the perspectives share a common look and feel, which helps you organize complex projects and focus on the task at hand. These perspectives are particularly useful if you need to access only a subset of the many capabilities available in the Rational Application Developer environment. Eclipse provides the capability to show features in a view only when you need them, so you can customize your perspectives. For example, you can show the tools that you use most often or other plug-in tools not included with the base product. So you can zoom in on just the Java application components, the Web components, the J2EE components, or the database-specific components in your project.

• Editors and wizards save you from tedious, time-consuming tasks

Rational Application Developer automates many tedious, routine tasks. It automatically creates a program structure that conforms to J2EE standards and configuration files for specific types of projects, such as Struts and portlets. Rational Application Developer can also create skeleton entities for business logic, such as Web services and EJB components. Wherever possible, Rational Application

Page 33: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

33

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Developer wizards and editors generate page-handling and component-interaction code, allowing you to focus on application functionality rather than low-level “plumbing.” Finally, there are drag-and-drop features for designing and developing GUI and Web interfaces with back-end databases.

The screen capture in Figure 7 shows the Data perspective in Rational Application Developer. The Data Definition pane displays an object view of the database components in the project. The Database Explorer pane displays the database connections and their status, and can be expanded to view the objects defined in that database. An editor pane showing an SQL procedure open for editing has tab views that let you focus on particular aspects of the database object being modified. At the bottom right, the status and message panes round out the information provided in this perspective. All in all you can see that the Data perspective provides a rich environment for which to build database applications.

Page 34: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

34

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 7: SQL stored procedure editor in Rational Application Developer

Design and view your data layout with data modeling toolsIntegrating Java applications with back-end database systems is always a challenge. The data in database systems typically has a predefined structure that must be brought into and accessed in the Java application. In some cases, developers unfamiliar with data modeling must develop the data structures themselves. Rational Application Developer provides tools that automate much of the coding for both data modeling and developing data structures. You can import a data structure from an

Page 35: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

35

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

existing data source or create a new data model with Rational Application Developer. Then, you can export the data structure to the actual data source. Rational Application Developer also provides a data perspective to organize all of these tools. Figure 8, shows how with a click of the mouse you can import a database definition from a server to a local project.

Figure 8: Copy database and database object definitions to a project with the Copy to Project feature

Page 36: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

36

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 9: DDL and SQL scripts can be run locally or deployed to database servers

Wizards help you create databases, database objects, and database connectionsGone are the days where you write the SQL to define databases and database objects from scratch! To create a database, create and manage the connections to it, or create a schema to organize the tables and other data objects, simply select a menu item to open a wizard, follow the wizard instructions, click the Finish button, and voila! To modify the SQL generated by a

Page 37: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

37

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

wizard, you can open the definition of the object in an editor to make and save your changes.

In relational database technology, schemas provide a logical classification of the named objects in the database, for example, tables, views, aliases, indexes, triggers, and structured types. Rational Application Developer provides wizards for defining tables, foreign keys, primary keys, SQL and external stored procedures, and user-defined function.

Figure 10: Table creation using the New Table Definition Wizard

Page 38: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

38

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 11: Visual display and alteration of primary and foreign keys

J2EE EJB component wizards and tools save you timeRational Application Developer has a number of data features and tools to speed up data management processes in J2EE programs, especially creating and mapping EJB components. You can use these tools with any major database, including DB2 UDB.

As an example, Rational Application Developer provides a wizard that generates connection code to let you visually bind the data to controls on a JSP. The wizard also generates an EJB session bean facade that you can use for writing code to access the Service Data Objects (SDO) DataGraph for EJB data.

Page 39: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

39

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

The EJB-to-RDB (relational database) wizard creates entity EJB components from a predefined data structure in a relational database, a process called bottom-up mapping. The tools in Rational Application Developer import the target data structure and handle all the mappings, which eliminates most of the coding in this type of EJB development.

Rational Application Developer also has wizards for top-down mapping of EJB development for both container-managed persistent (CMP) JavaBeans and bean-managed persistent (BMP) JavaBeans. After defining the data structure, you can map it to the data source using a simple Map Browser (Figure 14) that shows the enterprise beans and the database tables side by side. When you drag and drop entities from the Enterprise Beans pane onto the database tables, Rational Application Developer creates all the underlying mapping code.

Page 40: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

40

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 12: The Map Browser speeds the creation and mapping of EJB components.

SQL Query Builder simplifies creating and executing SQL statements The SQL Query Builder provides a visual interface for creating and executing SQL statements--from very simple statements to complex expressions and groupings. It also provides an SQL-to-XML wizard to generate XML artifacts for use in other applications, such as a servlet or JSP.

In a graphical view of the tables and columns in the database, you can select which columns to work with, link them to specific join operations, and build expressions to qualify the data to be

Page 41: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

41

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

retrieved. You can also execute a query directly in the editor to verify that it works as intended, define host variables that the user enters, and call stored procedures from the query.

Figure 13: Visual specification of SQL query in the SQL Query Builder

Page 42: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

42

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

SQL syntax highlighting and code assist make writing SQL easierIf you want or need more control over SQL queries, the SQL Editor provides the same features as the Code Editor (such as syntax highlighting and code assist) help you write queries by hand by identifying whether a column name or database object name is valid within the specified schema or by highlighting recognizable programming errors. Rational Application Developer also has special code editors for writing SQL stored procedures and user-defined functions (UDFs) for DB2 UDB.

Figure 14: New SQL Stored Procedure Wizard

Page 43: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

43

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Tools make creating, building, debugging, and deploying SQL stored procedures easyYou have end-to-end SQL stored procedure support in the Rational Application Developer data perspective. You can create your stored procedures using wizards, and SQL stored procedure debugging features enable you to detect and diagnose errors in running SQL procedures on a local or remote database server. You can control the execution of your code by setting line and variable breakpoints, suspending execution, step through the code, and examining the contents of variables. The DB2 UDB stored procedure debugger supports debugging on DB2 UDB for Linux, UNIX, and Windows, DB2 UDB for z/OS, and DB2 UDB for iSeries servers. After you build an SQL stored procedure in debug mode, you can start the debugger and step through the source code.

Remote debugging allows you to run the stored procedure on one system and control it from your workstation. Remote debugging is useful for a variety of reasons:

• On another system, stored procedures might behave differently than they do on your local system. The remote debugging features lets you control and observe the internal behavior of the remote stored procedure from your local system.

• The debugger UI might not run on the platform on which you have compiled the stored procedures. You can use the remote debugging feature to take advantage of the debugger UI on your local computer while debugging the stored procedure running on the remote computer.

Page 44: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

44

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Deployment wizards and tools make it easy to export SQL procedure definitions and deploy them to production servers quickly and easily, rounding out your SQL procedure development support

The ensemble of Java application development tools in Rational Application Developer gives you a complete toolbox for developing all kinds of Java applications. This tooling provides extensive support for developing database applications and working with database objects from a clean, well-organized interface. Altogether, this powerful, flexible, easy-to-use toolset makes end-to-end Java database application development fast and easy.

Start small and gradually grow your Java application development toolsIf you don’t need a complete Java IDE yet, you can start your database application development by downloading the basic Eclipse Platform for free from www.eclipse.org. You can extend this framework with plug-ins made available by members of the Eclipse community. IBM provides a free IBM Web Tools plug-in that can be used for developing Web applications with back ends that connect to DB2 UDB, Apache Derby, and IBM Cloudscape databases, and application servers. This tooling offers you a subset of the features in Rational Application Developer that you can download and use right away. Of course, you won’t have the full suite of Java and J2EE development features available in Rational Application Developer, but the free plug-in gives you an easy way to see what Eclipse based products and the Rational Application Developer tooling have to offer.

Page 45: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

45

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

IBM Web Tools has tools very similar to those available in IBM WebSphere Application Server, which makes it easy to reuse skills for managing objects and applications in another IBM product environment. As the complexity and size of your applications and your organization grow, you can always adopt Rational Application Developer, with no loss of skills or resource investment.

DB2 UDB Development Center supports stored procedure and User Defined Function developmentIf you don’t primarily develop Java applications and only need to work with stored procedures and database objects, there is extensive tooling available for you in the DB2 UDB Development Center, which comes with the free DB2 UDB Application Development Client.

The DB2 UDB Development Center provides a rapid, iterative development environment for building stored procedures and user-defined functions (UDFs). It supports both workstation and mainframe DB2 UDB database products.

With the DB2 UDB Development Center, you can:

• Create, build, and deploy Java and SQL stored procedures • Create, build, and deploy UDFs (for Linux, UNIX, and

Windows operating systems): • Develop SQL and Java UDFs that:

¡ Read MQSeries messages¡ Access OLE DB data sources

Page 46: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

46

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

¡ Extract data from XML documents ¡ Debug SQL stored procedures using the integrated

debugger (DB2 UDB V8 for Linux, UNIX, Windows, and z/OS operating systems)

• See the contents of the server for each database connection that is in your project or that you explicitly add to the Server View

The latest version of the DB2 UDB Development Center offers improved functionality, including concurrent task execution, flexible window docking, enhanced scalability, a range of new wizards that simplify development tasks, and an easy-to-use interface designed to improve productivity.

The screen capture in Figure 15 shows how easily you can configure a database connection in the DB2 UDB Development Center when you first create a project. Simply follow the steps in the Create a Project wizard, and you’ll have created a connection with which you can build, test, and run your stored procedures.

Page 47: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

47

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 15: Configuring a database connection using the Create a Project wizard.

Creating a stored procedure or user-defined function can also be done with a few simple mouse clicks or by using a wizard, such as the Create SQL Stored Procedures wizard shown in Figure 16. In this wizard, you can create the SQL procedure-body logic by reusing SQL fragments that you have saved from previous work or by using the SQL Assist wizard.

Page 48: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

48

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Figure 16: Creating SQL stored procedures using the Create SQL Procedures wizard.

Once you complete the wizard steps, the CREATE PROCEDURE statement required to create your stored procedure is automatically generated for you and displayed in the Editor View. For a Java stored procedure, the essential source code required to implement it is also generated. These features save you time and help prevent syntax errors.

Once you have developed your stored procedure or UDF, you can save, build, and run it to check that it functions properly. If it doesn’t work quite right, you can build it in debug mode

Page 49: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

49

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

and identify the potential problem by using the debugger in the Editor View toolset shown in Figure 17. You can use the Output View to see the status of the last action you took, as well as the status of previous actions.

Figure 17: Debugging SQL procedures in the Editor View of the DB2 UDB Development Center.

With the debugging tools, you can set breakpoints, watch variable values as they change, step into statements (including nested calls to other stored procedures), run to the breakpoint, and more. The same features are available for debugging both SQL and Java stored procedures and UDFs.

Once you are satisfied that your routine is functioning properly,

Page 50: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

50

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

you can use the DB2 UDB Deployment Wizard to deploy the routine quickly to various production database servers. Thus, the DB2 UDB Development Center provides end-to-end support for developing stored procedures with an easy-to-use interface.

DB2 UDB satisfies Java application development needsJava application developers are increasingly having a say in what database their enterprise’s applications run on and given the available choices DB2 UDB provides everything to satisfy the Java developer’s needs.

• DB2 UDB is an extremely reliable database for Java database applications¡ DB2 UDB databases support high availability database

applications¡ DB2 UDB databases support application scalability¡ DB2 UDB databases can be installed on many different

platforms¡ DB2 UDB databases ensure Java applications perform

well

• DB2 UDB provides unparalleled Java database application and feature support¡ DB2 UDB supports the latest Java technology ¡ DB2 UDB Universal JDBC Driver provides unparalleled

JDBC support¡ DB2 UDB supports both JDBC and SQLJ APIs¡ DB2 UDB supports the latest JDKs and JREs¡ DB2 UDB supports the Java 2 Platform, Enterprise

Page 51: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

51

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

Edition (J2EE) specification¡ DB2 UDB supports Java and SQL stored procedures &

user-defined functions

• DB2 UDB tooling makes developing Java database applications fast and easy¡ IBM products and tools are Eclipse based and thus highly

inter-operable¡ IBM Rational Application Developer IDE has fully

integrated DB2 UDB tool support¡ IBM Rational Application Developer IDE has complete

suite of J2EE tools¡ IBM Websphere Application Server comes with fully

integrated DB2 UDB tools¡ DB2 UDB Development Center provides standalone Java

& SQL procedure tools¡ IBM Web Tools provides free Eclipse plugin tooling for

building Java web applications that access DB2 UDB databases

For all of these reasons, it is no wonder why Java developers regularly pick DB2 UDB as their database of choice. DB2 UDB database features make it a database that you can trust your applications to run on successfully under different loads and in different conditions. DB2 UDB reliability, availability, scalability, and a reputation for top of the industry Java performance all bring peace of mind to Java developers who want to focus their time and energy, not on the database, but on application development. DB2 UDB tooling support within the product and seamlessly integrated into related IBM and open

Page 52: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

52

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

source Eclipse products provide developers with support from the application design stage through to deployment. IBM has adopted the philosophy that rather than providing independent tools, it is better to bring related tooling together first and then to you. As a Java developer, if you don’t have to worry about the database and if you have all of the tools you need in one place, Java database application development becomes easier. And when it is easier it also tends to be faster--not to mention more fun!

ResourcesGeneral• IBM DB2 Universal Database for Linux, UNIX, and

Windows http://www-306.ibm.com/software/data/db2/udb/

Page 53: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

53

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

• IBM DB2 UDB product documentation in HTML format with search capability: http://publib.boulder.ibm.com/infocenter/db2help/index.jsp

• Eclipse open source site: www.eclipse.org

• Cloudscape - Frequently asked questions: ftp://ftp.software.ibm.com/software/data/cloudscape/pubs/cloudscape-partner-faq.pdf

Reliability• IBM DB2 UDB product documentation in PDF format:

http://www-306.ibm.com/software/data/db2/udb/support/manualsv8.html

• IBM DB2 DB2 UDB High Availability and Disaster Recovery: http://www-306.ibm.com/software/data/db2/udb/hadr.html

• Configure IBM DB2, SAP, and the High Availability Feature for a 15 second failover solution: ftp://ftp.software.ibm.com/software/data/highlights/ha.pdf

Java support• Developing Enterprise Java™ Applications Using DB2®

Version 8 http://www-306.ibm.com/software/data/db2/udb/support/manualsv8.html

Page 54: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

54

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

• IBM DB2 Universal JDBC Driver: http://www-306.ibm.com/software/data/pubs/papers/sqlj/

• IBM DB2 Universal JDBC Driver product documentation: http://publib.boulder.ibm.com/infocenter/db2help/topic/com.ibm.db2.udb.doc/ad/t0010264.htm

• IBM DB2 application development documentation http://www-306.ibm.com/software/data/db2/udb/ad/

• IBM Rational Application Developer 6.0 – an overview http://www-306.ibm.com/software/info/developer/radrwd/index.jsp

Development tooling• Rapid Java and J2EE Application development with IBM

Web Sphere Studio and IBM Rational Developer: http://www3.software.ibm.com/ibmdl/pub/software/rational/web/whitepapers/wp-radrwd-medres.pdf

• Rational Application Developer and Rational Web Developer trial program: www.ibm.com/developerworks/websphere/downloads/WSsupport.html

• IBM Web Tools for Eclipse http://www.alphaworks.ibm.com/tech/webtools?open&S_TACT=105AGX59&S_CMP=GR&ca=dgr-jw26awwebtools

Page 55: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

55

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

About the authorGwyneth R. Evans (BSc.) is a software and information developer specializing in DB2 Universal Database for Linux, UNIX, and Windows. She is a DB2 Certified Database Administrator and Application Developer. She presents in-depth sessions at DB2 Information Management Software and IDUG conference and contributes articles to developerWorks. She specializes in SQL and DB2 application development.

NoticesIBM, DB2, DB2 Universal Database, IMS, Lotus, Lotus Notes, Rational, Websphere, z/OS, iSeries, and zSeries are trademarks or registered trademarks of International Business Machines Corporation in the United States, other countries, or both.

Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.

Microsoft and Windows are registered trademarks of the Microsoft Corporation in the United States, other countries, or both.

Other company, product, and service names may be trademarks or service marks of others.

Copyright International Business Machines Corporation, 2004. All rights reserved.

The contents of this article represent those features that may

Page 56: DB2 UDB and Java: Fast, - Haaga-Helia ammattikorkeakoulumyy.haaga-helia.fi/~dbms/db2/04_Resources/Docs/AD_Java_eBook.pdf · DB2 AND JAVA EDITION DB2 UDB and Java: Fast, Easy, and

56

D B 2 A N D J AVA E D I T I O N

DB2 UDB and Java: Fast, Easy, and Reliable Database Application Development

or may not be available in the product. The views expressed in this article are those of the author and not necessarily those of IBM Canada Ltd. or IBM Corporation.