Java Reference
In-Depth Information
T ABLE 20.1
Required Attributes to Model a Movie
Attribute
Type
title_id
int
title_name
String
price
double
quantity
int
category
int
To make the Titles table available to your application you must set up an ODBC data source
following the same steps used in Chapter 7 “Servlets, JDBC, and Inter-Servlet
Communications.” You will need to use catalog as the data source name and select the
catalog.mdb file included in this chapter's source code.
To complete your configuration of the database you will need to create a servlet that initializes
the ConnectionPool created in Chapter 7 with the appropriate setting for this application.
The source for the extension of the ConnectionPoolServlet is in Listing 20.1.
L ISTING 20.1
CatalogConnectionPool
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import ConnectionPool.ConnectionPool;
public class CatalogConnectionPool extends HttpServlet {
//Initialize global variables
public void init(ServletConfig config)
throws ServletException {
super.init(config);
// Instantiate the ConnectionPool
ConnectionPool pool = new ConnectionPool();
try {
// Set the JDBC Driver
pool.setDriver(“sun.jdbc.odbc.JdbcOdbcDriver”);
pool.setURL(“jdbc:odbc:catalog”);
pool.setSize(2);
20
// Set the Username
pool.setUsername(“”);
 
Search WWH ::




Custom Search