"The Application Server Marketplace: Which Model is Right for You?"
by Steve Benfield
Web Techniques, January 1999

Web Techniques grants permission to use these listings (and code) for 
private or commercial use provided that credit to Web Techniques and 
the author is maintained within the comments of the source. For 
questions, contact editors@web-techniques.com. 


import java.sql.*;  
import java.io.*;
import com.sybase.jaguar.jcm.*;
import com.sybase.jaguar.util.*;
import com.sybase.jaguar.sql.*;
import com.sybase.jaguar.server.*; 
public class Customer extends Object {
   public void retrieve() {
   ResultSet  rs = null ;
   boolean    rc = false ;
      try {
         // Call the Jaguar cache manager to get a cache entry
         JCMCache Cache = JCM.getCache( "dba", "sql",
         // create a JDBC connection; if a connection isn't available
         Connection connection = Cache.getConnection(JCMCache.JCM_FORCE);
         Statement stmt = connection.createStatement();
         stmt.execute( "SELECT company_name, id FROM customer 
                        ORDER BY company_name" );
         rs = stmt.getResultSet();
         // Send the result set to the Jaguar Server
         if ( rs != null ) JContext.forwardResultSet( rs ) ; 
         // Release the database connection back to the pool
      } catch (JException je) {
      } catch (SQLException e) {
      } // END OF THE TRY
}  // end of retrieve method


<!--- This template adds a specified quantity of a certain item to the
      shopping cart.  The item is indicated by Form.ItemID and the quantity
      to be added is indicated by Form.Quant --->
<!--- Begin code that actually adds the item --->
    <!--- If the item is already in the basket... --->
    <CFIF ListFind(Session.StoreItems, Form.ItemID) NEQ 0>  
        <!--- Find where in the basket it is --->
        <CFSET ItemPosition = ListFind(Session.StoreItems, Form.ItemID)>
        <!--- Find out how many of the item are already in the basket --->
        <CFSET CurrentQuantity = ListGetAt(Session.StoreQuantities, ItemPosition)>
        <!--- Now we add one to what's already in there --->
        <CFSET Session.StoreQuantities = ListSetAt(Session.StoreQuantities, 
                                                   ItemPosition, CurrentQuantity + 1)>   
    <!--- Otherwise, just add it to the basket --->
        <CFSET Session.StoreItems = ListAppend(Session.StoreItems, Form.ItemID)>
        <CFSET Session.StoreQuantities = ListAppend(Session.StoreQuantities, 1)>   
<!--- End code that adds the item --->
<!--- Declare a QUERY against the Cfexamples table. Use the Form.ItemID to find
      the current Item. ---!>
    SELECT ItemName FROM StoreItems
    WHERE ItemID = #Form.ItemID#
<HEAD><TITLE>Online Store - Shopping Cart</TITLE></HEAD>
 background="images/storebg.gif" leftmargin=5 topmargin=0>
<!--- Generate the output for the GetItem query. Notice how variables are embedded
      in code by using the pound signs ---!>
    alert('A(n) #ItemName# was added to your shopping cart.')
<!--- Show the items and cart the show the items the user has selected; 
      these pages would have been created earlier in the tool ---!>
<SPAN STYLE="position: absolute; left: 205px; top: 15px; width: 350px;">
    <CFINCLUDE TEMPLATE="_showitems.cfm">
    <CF_ShowDoc ID=3>
<CFINCLUDE TEMPLATE="_showcart.cfm">