InfoCenter Home >
4: Developing applications >
4.2: Building Web applications >
4.2.4: Putting it all together (Web applications) >
4.2.4.2: Obtaining and using database connections >
4.2.4.2.2: Accessing data with the JDBC 1.0 reference model

4.2.4.2.2: Accessing data with the JDBC 1.0 reference model

The reference model that uses the JDBC 1.0 APIs, which still work under JDBC 2.0 and Application Server Version 3.x, is based on the code fragments shown in the following steps:

  1. Load the driver for a specific relational database product. The specific driver class should be available from the WebSphere administrator.

    This step is typically performed once, during the init() method of the servlet.

    Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
  2. Use the static getConnection() method of the DriverManager class to get a JDBC connection to the relational database product, again using parameters for the specific database product. The WebSphere administrator can provide the subprotocol, database, user ID, and password information.

    This step is performed for each client request made to the servlet, typically in the doGet() or doPost() method. (The subprotocol and database information are combined into what is called the database URL, shown as "jdbc:subprotocol:database" in the following code.)

    Connection conn =
    DriverManager.getConnection("jdbc:subprotocol:database",     // database URL
    "userid",
    "password");
  3. Given the connection, do the necessary data server interactions for each client request. This step is typically performed in the doGet() or doPost() method.

  4. At the end of each client request, free the connection resource. This step is typically performed at the end of the doGet() or doPost() method.
    conn.close();
Go to previous article: Handling data access exceptions Go to next article: Accessing relational databases with the IBM data access beans

 

 
Go to previous article: Handling data access exceptions Go to next article: Accessing relational databases with the IBM data access beans