Logo

You're here: Home » Java » MySQL and Java Developer's Guide

MySQL and Java Developer's Guide


by Mark Matthews, Jim Cole, Joseph D. Gradecki | ISBN 0-471-26923-9 | 2003, Wiley Publishing

The primary goal of MySQL and Java Developer’s Guide is to provide a comprehensive approach to writing code from a Java application to a MySQL database using the industry standard: JDBC. As you will see later in this Introduction, the chapter titles indicate what area of database connectivity and manipulation they cover. The chapters are ordered to reflect the JDBC specification, but we aren’t here to simply describe the specification.
We wrote all of the material in the book to highlight how MySQL’s Connector/J JDBC driver achieves the interfacing of MySQL with Java while maintaining the spirit of the specification. With this in mind, we provide example code using all major forms of Java development, including:
¦¦ Applications
¦¦ Applets
¦¦ Servlets
¦¦ JSPs
¦¦ EJBs

As you work in Java and JDBC, you will see the true power of the specification. You can write database access code in a Java application and move the code to a servlet with little if any changes. In the case of EJBs and container-managed persistence, we devoted a full chapter to dealing with database access without the cumbersome details of SQL.

We designed the layout of the book to move you through the entire process of writing Java code needed to access a back-end database. Developing the database is one of the first things that you must accomplish in this process. Whilewe don’t delve deeply into the theory of database development, you learn how to create databases in MySQL, administer those databases, and handle such details as granting access permissions. From there, we take you into an examination of the MySQL Connector/J driver and how it accomplishes its goal of portable database access. The remainder of the book steps you through Java code that highlights how to accomplish database tasks such as the following:
¦¦ Querying and updating
¦¦ Handling ResultSets
¦¦ Using transactions
¦¦ Handling typing issues between JDBC and MySQL
¦¦ Working with metadata
¦¦ Addressing efficiency issues

Once you’re familiar with these concepts, we present a complete application that pulls it all together. Our application illustrates how you can create to a simple authorization service. Using a combination of JSP, servlets, and EJBs, the service allows new users to create accounts, recall the account, and verify a username/password combination. The system is designed to be interactive using JSP pages, which are handled on the server using servlets. The JSPs can be bypassed using the servlets directly. All of the critical information is kept on the database for persistence and management needs.

After reading this book, you should know how to interface Java to MySQL and be able to use the many examples for reference.

Table of Content
Chapter 1: An Overview of MySQL
MySQL is one of the most popular open source database systems available today, and it is used as the back-end data storage device for many personal and corporate Web sites. Java is the most portable language in use today and continues to be improved with each new release. In this chapter, we provide a brief overview of each product and begin the discussion of how to interface the two and thus allow Java applications to have access to a vast array of information.

Chapter 2: JDBC and Connector/J
As shown in Chapter 1, JDBC facilitates the interface between Java and
MySQL. The JDBC specification defines the interfaces and classes necessary for any Java application, applet, servlet, and so forth to make calls to an underlying database. Because the JDBC specification isn’t specific to any one database system, manufacturers create JDBC drivers for their specific database. In this chapter, we discuss the history of JDBC, how it started, and its progress into a version 3.0 specification. We examine in depth the MySQL JDBC driver called Connector/J, and look at its history as the MM.MySQL JDBC driver as well as its future.

Chapter 3: Working with MySQL SQL
Before we delve into the concepts surrounding the interface between Java
and MySQL, this chapter provides a basic overview of databases and SQL.
Topics include basic concepts behind databases, simple database design, database normalization, and data manipulation.

Chapter 4: Installing MySQL, Java, and Connector/J
All of the coding examples in this book are built using MySQL as the primary database, Java as our coding language, and Connector/J, MySQL’s JDBC driver. Although the installation of these components isn’t overly difficult, this chapter provides comprehensive instructions for obtaining all of the necessary components and performing a step-by-step installation. We also provide simple examples for testing the installation.

Chapter 5: Using JDBC with Java Applications and Applets
This chapter is the first in a series on the use of Java to access a MySQL database using JDBC. Some of the basic functionality discussed includes loading the JDBC driver, connecting to a local or remote database, building JDBC statements in preparation for queries, uting queries against the MySQL database, working with ResultSets, and accessing MySQL-specific functionality through JDBC.

Chapter 6: Achieving Advanced Connector/J Functionality with Servlets
At this point, you’ve learned the basics, and it’s time to expand into the more advanced topics. This chapter is designed to expand your understanding of SQL, MySQL, and JDBC. The topics include updatable ResultSets, Prepared- Statements, date/time types, BLOBs and CLOBs, and joins.

Chapter 7: MySQL Type Mapping
One of the fundamental issues associated with databases and programming language is determining the correct mapping from one to the other. While programming languages have a large variety of types, including simple ones like integer, they also allow more complex ones, like classes. Databases, on the other hand, are limited in their choices for the types of data that can be stored. In the middle of this situation is the JDBC driver. This chapter discusses the types available on the MySQL database, how JDBC interprets those types, and the resulting Java type produced by the mapping.

Chapter 8: Transactions and Table Locking with Connector/J
In a simple world, information is stored in a single table of a database. When you have to update information or insert a new row, you can use a single query. However, most modern databases store information across several different tables to increase the normalization of the tables. In this situation, when you have to update information or insert new rows, you must write two queries instead of one. This chapter looks at inserting multiple pieces of information into multiple tables, what problems can arise, and how transactions can be used to solve these problems.

Chapter 9: Using Metadata
After a query is performed against a MySQL database, the information is
returned in a ResultSet object. This object includes all of the rows and columns specific to the query performed. In many cases, additional information is needed about the data, including the name of the columns in the result, the precision of the data in a float column, the maximum length of a column, and maybe even information about the server from which the data was returned. In this chapter, we discuss pulling metadata about both the database and a Result- Set that contains information from a query.

Chapter 10: Connection Pooling with Connector/J
In many cases, a JDBC driver requires between 4 and 10 different communications with a database application before a connection can be established and returned to the requesting application. If an application is constantly creating connections, doing its business, and then closing the connection, the application suffers in its potential performance. To overcome the connection performance problem, you can use a connection pool. This chapter provides a comprehensive introduction to connection pools, presents valuable statistics for creating database connections, and demonstrates how to use the connection pooling mechanisms within JDBC.

Chapter 11: EJBs with MySQL
Enterprise JavaBeans (EJBs) provide the framework for building applications that can handle the rigors of enterprise-level applications. In addition, EJBs can be distributed across a network or a farm of servers. In this chapter, we cover the basic EJB programming model, using DataSources and JNDI, and building session beans to access MySQL. We also discuss container-managed persistence and bean-managed entity beans.

Chapter 12: Building a General Interface for MySQL
All of the chapters to this point have featured relatively simple examples using Java applications, applets, servlets, and JSP to illustrate the finer points of accessing a MySQL database using Java and Connector/J. This chapter pulls it all together using a Certificate Authority application. Using JSP, servlets, and EJB, the application shows how to create new accounts, request certificates, and enable the verification of certificates. All of the information, including the binary certificate, is stored in a MySQL database with multiple tables.

Chapter 13: DatabaseAdministration
Once you have a good knowledge of the MySQL database system as well as the fundamentals described in the previous chapters for accessing the data from Java, you must learn some database administration basics. In this chapter, we examine many of the functions within MySQL that benefit administrators, such as granting/revoking permissions, providing security within the server, and recovering from disasters.

Chapter 14: Performance and Tuning
Once the application is written and the information is safely sitting in a database, the users get the final say on whether or not the application meets their performance requirements. If the application isn’t running at an appropriate level, you have a couple of options. First, you can profile the Java code to determine where the application is spending the most time and then rework the code associated with the problem areas. Second, you can tune the MySQL server and create indexes for the database tables. In this chapter, we provide the necessary information on performing these two options.

Appendix A: MySQL Development and Test Environments
We developed and tested all of the code in this book on several different test architectures in order to provide a representative reference. This appendix briefly describes those environments and lists the installed software. In addition, we offer some notes for reproducing the configuration.

Appendix B: Databases and Tables
In this appendix, we list all databases and tables used in the examples
throughout this book.

Appendix C: The JDBC API and Connector/J
This appendix is a comprehensive review of the entire JDBC API, with annotations for Connector/J. Code snippets are provided to show at a quick glance how to use the various interfaces, classes, and methods.

Appendix D: MySQL Functions and Operators
The list of MySQL functions and operators in this appendix will help you determine when the database should handle computations versus the application. Each function and operator is described, and an example of its use is given.

Appendix E: Connector/J Late-Breaking Additions
The most current, up-to-date additions to Connector/J as it moves from gamma to production version.

Look Inside The Book



Tag: java,mysql,Java books,Java tutorials,Java references,JDBC API,Connector/J,MySQL Development,Enterprise JavaBeans,EJBs,JDBC,Java Applications,Java Applets

Date: 04/04/2006 • Views: 273 • Downloads: 80 • Rating: 0 (0 Votes)
Download MySQL and Java Developer's Guide (1.9MB)Report ProblemRecommend this file to a friend

Rate this file

Lowest Highest

Partners: Links | Links 2
Script by Olate Download 3.4.3 | RSS


 


Your Ad Here



Anwarica.com
Link Exchange
Graphatia
Yuk Ngeblog!
Download.web.id