Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
462
Chapter 18 JDBC and Database Connection Pooling
Core Note
JDBC is not an acronym.
Although a complete tutorial on database programming is beyond the
scope of this chapter, I'll cover the basics of using JDBC here, assuming
you are already familiar with SQL. For more details on JDBC, see
http://java.sun.com/products/jdbc/
, the on line API for 
java.sql
,
or the JDBC tutorial at 
http://java.sun.com/docs/books/tutorial/
jdbc/
. If you don't already have access to a database, you might find
mySQL a good choice for practice. It is free for non Microsoft operating
systems as well as for educational or research use on Windows. For details,
see 
http://www.mysql.com/
.
18.1 Basic Steps in Using JDBC
There are seven standard steps in querying databases:
1. Load the JDBC driver.
2. Define the connection URL.
3. Establish the connection.
4. Create a statement object.
5. Execute a query or update.
6. Process the results.
7. Close the connection.
Here are some details of the process.
Load the Driver
The driver is the piece of software that knows how to talk to the actual data 
base server. To load the driver, all you need to do is to load the appropriate
class; a 
static
 block in the class itself automatically makes a driver instance
and registers it with the JDBC driver manager. To make your code as flexible
as possible, it is best to avoid hard coding the reference to the class name. 
These requirements bring up two interesting questions. First, how do you
load a class without making an instance of it? Second, how can you refer to a
class whose name isn't known when the code is compiled? The answer to
both questions is: use 
Class.forName
. This method takes a string represent 
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Jsp Web Hosting Cheapest Web Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved