Distributed Java 2 Platform Database Development, 1st edition
Authors: Stewart Birnam
Venue:  (2000)

From the Book:PREFACE: PrefaceQuick StartThis book covers JDBC, RMI, Swing, servlets, and command-line programs and how to tie them all together to build a system using an Oracle database and the Linux operating system. The first few chapters are mostly background information on multitiered systems. Subsequent chapters cover specific technologies and how you can reuse code used to access a database in Swing applications or servlets.Oracle is used exclusively in all the examples that have to do with accessing a database. Examples of simple querying as well as complex joins are covered. Inserts, updates, and deletes of regular data  as well as how to store Web images as BLOBS in the database  are all shown in detail. Oracle-specific features of SQL, such as use of the CONNECT BY statement in hierarchical tables, is shown. Displaying parent-child relationships in GUIs via the Swing Jtree object is explained.All the example code was developed on Red Hat Linux 6.1, although the code would work on any Java 1.1 capable platform, which is just about everything these days. Particular attention is given to crafting shell scripts and makefiles to make deployment and development easier. The Oracle database is version 8, running under Linux. Examples of making system calls to Unix commands, as well as building sysadmin remote monitoring tools, are also given.IntroductionMany books on Java technology exist in the marketplace. A good chunk of these are aimed at teaching the fundamentals of the language. The rest take the tack of choosing a particular API and providing an in-depth tour. Very few of these books tell you how to integrateallthese APIs and technologies and actually build a deployable system. Even fewer books talk about solving very specific problems, like accessing an Oracle database. In fact, I couldn't find a single example of this, and I looked very, very hard. Faced with having to get the job done, I ended up as many before me have: embarking on a massive research project to find and accumulate all the information and techniques I needed to build the application I wanted to build. Having done that, I decided that others might be saved the trouble I went through, by sharing the knowledge that I found hiding in so many nooks and crannies. So I wrote this book.This book is about building systems with Java technology. Building successful real-world systems involves more than just an efficient algorithm or some clever coding tricks. It means building scalable, efficient, maintainable code, that may or may not integrate an existing system or software package, such as Oracle. With the prevalence of the Internet, your software will most certainly need to make use of the Internet and utilize established Internet protocols. In addition, you need to be able to efficiently administer, deploy, and document your system in a timely manner. Without good administration or deployment, your system is unusable and probably perceived as unstable as well. My intent is to show you how you can solve these problems, as well as address the actual application issues, with a combination of open standards and Java technology. To illustrate these concepts, technologies, and their use, we will build a distributed database application system that uses an Oracle database.With all the industry buzz concerning Linux recently, I set out to see if all these techniques could be applied under Linux. I'm glad to report that the Java implementations under Linux are strong and robust. Oracle now has a release of their database for Linux as well. In the last few months, all of the "gotchas" that came with deploying Java under Linux have been resolved. Java runs under Linux without any significant differences from any other Unix platform.Why a Distributed Database Application System? Distributed computing is becoming more prevalent, thanks to the Internet and the proliferation of cheap PCs. It's no secret that the Internet is changing our lives. One interesting side effect of everyone's great interest in the Internet is the amount of computing power that now sits mostly idle, waiting for someone to click on a Web page or strike a key. Furthermore, never before has it been possible to acquire so much computer for so little price. With the network gluing all these machines together, it's now possible and important to consider distributing problems across multiple heterogeneous computers.Database application development is by nature distributed, and almost all companies and organizations have a need for database access. A database is something you want to share. The number of people and organizations you may want to share it with may vary, but chances are the information needs to move across and be accessed by multiple systems. Even if you're implementing a two-tiered database model today, you're still distributing the work by moving the presentation layer off the server and to the client. It's an attractive idea to make the client do more work, thus enabling your server to service a greater number of requests by offloading more of its workload to the client.Delivering a working distributed database application system calls for the integration of many APIs and technologies. You can understand all the reasons for wanting a distributed application, but implementing one requires a knowledge of networking, database programming, systems administration, GUI programming, systems programming, and Web programming  all areas in which there isn't typically a lot of skills overlap. Individuals specializing in one discipline may have almost no knowledge or experience with another. It can be difficult to pull together a team that can cover all the bases. It can be even harder to coordinate all their efforts efficiently toward the completion of a common goal.Java has a huge collection of APIs that address all these areas and more. While other languages offer similar capabilities, I can think of no other that provides so many useful and well-documented classes as part of their core API. Companies and organizations have an increasing need to access data from potentially distant and heterogeneous systems. E-commerce dictates the need for organizations to communicate with each other without the necessity of identical hardware or software. Java technology, with its strength in network programming and cross-platform "write once run anywhere" capabilities, is uniquely suited to address this problem. In addition, scientific and technical computing can also benefit from this technology by enabling collaboration all over the world.Today's market requires flexible systems to respond to swiftly changing needs of the organization and consumers. The pace of technology and systems today is astonishing. It is fairly evident that in order to maintain any kind of production environment you will always be integrating new technology with old, and new systems with existing systems. In addition, not only may your systems be changing rapidly due to technical reasons, but you may also be changing the way that you do business just as rapidly. Your systems need to be designed in such a way to accommodate this. Object-oriented programming and Java technologies can help you build systems toward this goal.You may still have to leverage the existing systems and resources. Many companies and organizations today still require expensive legacy systems, or have legacy applications in place for some departments because of a vertical application and/or significant training investment. Often there are also political factors as to why one technology is adopted over another, and those technologies may change from department to department. Spreadsheets, e-mail, text files, and databases all abound as individuals in the organization build their own systems based on their needs and skill levels.Typically in this environment, you may have programmers scattered across the organization, coding in a variety of languages on multiple platforms. In an early effort to get information to flow from one division to another, several patchwork systems may have evolved. This kept things moving, but as the needs of the organization changed, it became harder and harder to implement new systems for fear of breaking the old ones. Not to mention that not everyone may be comfortable with dropping his or her system in favor of someone else's, and potentially losing the control they may have had.A key focus of this book is the belief that systems need to be able to react swiftly to the changing needs of the organization. Their architecture needs to be designed to reflect this. Many organizations  including startups, nonprofits, media, scientific/engineering environments, and others  may also have the additional constraint of limited budget and/or nontraditional business models that make out-of-the-box solutions impossible or prohibitively expensive. Moreover, it may be necessary to integrate many types of data storage methods in an effort to bring the departments together into a centralized information base.Can Java Technology Help Me Build Systems?This book is an answer to that question, and sets out to design a new system that maintains flexibility while respecting the needs of various users. We accomplish this by building and designing our business applications and systems with Java technology using a distributed computing model. Java's strength as a network programming language, its cross-platform nature, and ability to interface natively with many vendor databases make the entire thing possible. Furthermore, the almost daily addition of more APIs for the Java environment makes its use more attractive than ever. Literally every facet of computing is covered, from XML to 3D, sound to Jini. There has never been a more widely used and supported set of APIs. Not to mention that most of these APIs have accessible source.Intended AudienceAre you: thinking of designing a distributed database system? in charge of an IS/IT department? a software developer looking to get an insight into some new technologies in order to help solve a particular problem? a budding programmer who's tired of poring over simple examples, and wants to see how everything integrates into a single, breathing system? If any one of these is you, then this book will help.If you're a software developer, this book will serve as a guide in building distributed systems. If you're a systems administrator, it will help you understand what the administration and maintenance issues for systems like these are. If you're an IT/IS manager, you can get a good understanding of the requirements in these kinds of systems, that will help you develop strategies and staffing/budget requirements for your projects.Whichever focus you have, this book will help you understand how all these complex issues blend together to build a system. Even if you decide not to do the core development yourself, but rather integrate turnkey solutions instead, you will be in a better position to evaluate those systems and perhaps even write the "glue" to hold them together after reading this book.Organization of This BookIn the beginning of each chapter you will find a quick outline in case you want to skip through, or quickly find some code snippet or piece of wisdom. Several chapters will have sections devoted to technology overviews, programming, administration, and support and deployment where relevant. In this way you will be able to safely skim through sections that may not be critical to you.For programmers, rather than take you on a tour of the various API specifications, I'm going to assume you're already familiar with the core API. That is, you've looked at other books in this series, have tried out some of the examples, but are still wondering how it all fits together. To that end you'll see throughout this book how the various Java APIs are brought together to create something real. In this respect alone, you may find this book valuable even if you don't intend to implement a complete system yourself. Understanding the fundamentals of how all the various components fit together will aid you tremendously in your evaluation of third-party solutions and/or development libraries.In addition, I'll show you how to integrate the software you build with existing, well-known open source and commercial systems. By the end of this book, you should have all the information you need to decide what pieces of the system you'll have to build and what pieces you can integrate. To get the most out of this book, you should have some familiarity with: Relational databases SQL (Structured Query Language  a nonprocedural language used to extract information out of databases) JDBC (Java Database Connectivity  part of the 1.1 and greater core API) HTTP NFS (Network File System  commonly used file sharing scheme under Unix) FTP Samba (An SMB system that runs on Unix servers, making it possible to share files to Win32 machines) SMTP (Simple Mail Transport Protocol  the underlying protocol for Internet e-mail)The Road AheadIn Chapter 1, we'll describe a distributed database solution implemented entirely in Java. It gives a high-level view of the server configuration, how the broker works, and how the various clients interact with the system. It focuses on hardware independence, and provides guidelines for determining the price/performance ratio of your system. Chapter 2 details the building of a database API to abstract the nuts and bolts of the database for the application programmer. We'll deal with ways you can encapsulate your SQL into an API.Chapter 3 deals with the construction of an RMI server, along with tips on how to administer it.Chapter 4 starts the discussion of client development by building a Swing application using the database API. General issues of using remote objects and Swing are discussed, with special attention to exception handling. Examples are given specific to populating GUI components with data from the database, like Lists, Tables, Trees, and ComboBoxes.Chapter 5 gives us a taste of how nice it is to be able to reuse your software by delivering access to the same database API via servlets. We also give a brief tour of the Apache JServ and Java Web Server from an administration and development perspective.Chapter 6 lets us now gorge ourselves in reusability by building a command-line client to provide an even easier way for script programmers or Web developers to access your database API. Chapter 7 shows you how to make your software distribution simple, and save you from walking to each machine and installing it. This is accomplished by some very well-known services (HTTP, FTP, NFS, and Samba), and some clever systems architecture and scripts.Chapter 8 gives a how-to on reading and writing BLOBS (Binary Large Objects) to the database. Special attention is given to delivering images and other multimedia content from BLOBs to servlets and applications.Chapter 9 illustrates how to build your own monitoring tools to help your administrators and support staff, as well as how to make system calls accessible via RMI.Running the Example CodeAll the examples in this book were developed and tested under Red Hat Linux 6.1. The database used was Oracle 8 for Linux. The JVM was the 1.1.8 Implementation for Linux from IBM. The examples were also tested with the Blackdown.org 1.1.6v5 JDK and with the Sun/Blackdown 1.2.2 Release Candidate 2.Check the following Web sites to download your own JDK for Linux: www.ibm.com/java  JDK 1.1.8 and JDK 1.3 www.blackdown.org  JDK 1.1.6v5 (the implementation preferred by Oracle) java.sun.com  JDK 1.2.2 Of course the examples will run under Windows NT, Windows 98, and Solaris as well. Oracle software is naturally available for NT, Solaris, and other flavors of Unix. You can download the Linux or other versions on a trial basis at technet.oracle.com.Oracle also makes a version of their software for Windows 95 and 98 called Oracle Lite, which you can use if you want to try the examples on that platform. Oracle Lite has a different JDBC driver than the regular Oracle database. Make sure you consult the documentation.If you're using a 1.1 JVM, you'll need to download the Swing libraries separately. You can find these at java.sun.com/jfc.The servlet examples were developed against Apache JServ 1.1b2 and run with the Apache Web Server 1.3.9, again under Linux. Apache JServ is an implementation of the 2.0 Java servlet specification. Sun is working with the Apache community and supporting the Jakarta effort that implements the 2.2 spec. Find out more about it at jakarta.apache.org or at Sun's Web site java.sun.com. There is a README file in the source distribution that will guide you in getting the examples running.