Explicitly closing the DB2 statement
The DB2 statement is automatically closed when the last result row is
reached or when the Java instance is terminated. In some cases, it is
desirable to immediately release a statement s database and JDBC
resources; the close method provides this immediate release as follows:
The bare minimum required to execute a simple DB2 query statement on the
USERINFO table, located in the USERSTUF database, is shown in Figure 67
on page 87.
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Db2Servlet extends HttpServlet{
public void doGet((HttpServletRequest req, HttpServletResponse res)
throws ServletException {
try {
Class.forName( COM.ibm.db2.jdbc.app.DB2Driver );
String url= jdbc:db2:userstuf ;
String uid= db2inst1 ;
String pwd= ibmdb2 ;
Connection con=DriverManager.getConnection(url, uid, pwd);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery( select * from userinfo );
// do something with the result set here
} catch (Exception e) {
Figure 67. Minimum code required to access a DB2 table from a servlet DB2 servlet AccessUserstuf
The AccessUserstuf servlet is responsible for all actions involving the
tables. As such, it must perform the following:
  At initialization (when it is first loaded by the WebSphere engine), it must
register the DB2 class library and create a connection to the USERSTUF
database. We have already discussed how to implement these in 3.5.3,
Chapter 3. Building the Web server



About Services Network Support FAQ Order Contact

Linux Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved