Java Reference
In-Depth Information
T
ABLE
22.1
Required Attributes to Model a Stock
Attribute
Type
symbol
String
price
int
bid
int
ask
int
22
To make the
stocks
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
trader
as the data source name and select the
trader.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 22.1.
L
ISTING
22.1
TraderConnectionPool
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import ConnectionPool.ConnectionPool;
public class TraderConnectionPool 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:trader”);
pool.setSize(2);