I still can't get the connection pooling manager to work. Any suggestions?
 
Thanks,
 
Ben Dudley
 
 
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import com.ibm.servlet.connmgr.*;
 
 
public class AS400Conn extends HttpServlet  {
 
   static IBMConnMgr connMgr = null;
 
   // Use later in init() to create JDBC connection specification.
   static IBMConnSpec spec   = null;      // The spec.
   static String db          = "*******";      // Database name.
   static String subprotocol = "as400";     // JDBC DB2 subprotocol.
   static String poolName    = "JDBCAS400"; // From Webmaster.
   static String jdbcDriver  = "COM.ibm.AS400.ACCESS.AS400JDBCDriver";
   static String url         = null;      // Constructed later.
   static String userid      = "*******";      // Userid and password can
   static String password    = "*******";      // come from HTML form.
  }
}
 
 
-----------------------------------------------------------------------------------------------------------------------------------------
 
public void init(ServletConfig config) throws ServletException
   {
   super.init(config);
     
  url = "jdbc:as400://" + "******";
  
 try {
  
    java.sql.DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
    
  // Load (and therefore register) the Access Driver
    Class.forName("com.ibm.as400.access.AS400JDBCDriver");
  
   // Create JDBC connection specification.
    spec = new IBMJdbcConnSpec
    (poolName,    // pool name from Webmaster
     true,        // waitRetry
     jdbcDriver,  // Remaining four
     url,         // parameters are
     userid,      // specific for a 
     password);   // JDBC connection.
  
  // Get a reference to the connection manager.
   connMgr = IBMConnMgrUtil.getIBMConnMgr();
    
   // Get a Connection to the database
   conn = DriverManager.getConnection(url, userName, password);
 
   }
 catch (ClassNotFoundException e) {
   throw new UnavailableException(this, "Couldn't load database driver");
 }   
 catch (SQLException e) {
  throw new UnavailableException(this, "Couldn't get db connection");
 }     
  
   }
 
------------------------------------------------------------------------------------------------------------------------------------
 
  public void doGet(HttpServletRequest req, HttpServletResponse res)
   {
   IBMJdbcConn cmConn   = null;
   Connection dataConn  = null;
   Vector firstNameList = new Vector();
   try
   {
   
   cmConn = (IBMJdbcConn)connMgr.getIBMConnection(spec);

   dataConn = cmConn.getJdbcConnection();
   Statement stmt = dataConn.createStatement();
    
   try { 
  
   String query = "SELECT * FROM GISFACT WHERE PCUNIT = 'SA1 1AA'";
  
 
   ResultSet rs   = stmt.executeQuery(query);
   
  while(rs.next())
   {
   firstNameList.addElement(rs.getString(1));
   
      }
 catch(SQLException e) {
   System.out.println("SQLException caught: " + e.getMessage());
 }
  
   }
   catch(Exception e)
   {
   System.out.println("get connection, process statement: " +
       e.getMessage());
   }
   finally
   {
   if(cmConn != null)
   {
   try
   {
      cmConn.releaseIBMConnection();
   }
   catch(IBMConnMgrException e)
   {
      System.out.println("release connection: " + e.getMessage());
   }
   }
   }
   // **********
   // * STEP 7 *
   // **********
   // Prepare and return HTML response - say Hello to everyone
   // whose last name is 'Parker' and address them with their first
   // and last name.
   res.setContentType("text/html");
   // Next three lines prevent dynamic content from being cached
   // on browsers.
   res.setHeader("Pragma", "no-cache");
   res.setHeader("Cache-Control", "no-cache");
   res.setDateHeader("Expires", 0);
   try
   {
   ServletOutputStream out = res.getOutputStream();
   out.println("<HTML>");
   out.println("<HEAD><TITLE>" + "empty" + "</TITLE><HEAD>");
   out.println("<BODY>");
  
   {
   for(int i = 0; i < firstNameList.size(); i++)
   {
      out.println("<H1>" + "greeting" + " " +
         firstNameList.elementAt(i) +
         " Parker</H1>");
   }
   }
   out.println("</BODY></HTML>");
   out.close();
   }
   catch(IOException e)
   {
   System.out.println("HTML response: " + e.getMessage());
   }
   }
 
 
 

Reply via email to