"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. 



[LISTING ONE]


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",
                                        "jdbc:odbc:marketingdata");
         // 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
         Cache.releaseConnection(connection);
      } catch (JException je) {
             je.printStackTrace();
      } catch (SQLException e) {
             e.printStackTrace();
      } // END OF THE TRY
}  // end of retrieve method


[LISTING TWO]


<!--- 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 --->
    <CFELSE> 
        <CFSET Session.StoreItems = ListAppend(Session.StoreItems, Form.ItemID)>
        <CFSET Session.StoreQuantities = ListAppend(Session.StoreQuantities, 1)>   
    </CFIF>
<!--- End code that adds the item --->
<!--- Declare a QUERY against the Cfexamples table. Use the Form.ItemID to find
      the current Item. ---!>
<CFQUERY DATASOURCE="CFexamples" NAME="GetItem">
    SELECT ItemName FROM StoreItems
    WHERE ItemID = #Form.ItemID#
</CFQUERY>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD><TITLE>Online Store - Shopping Cart</TITLE></HEAD>
<BODY BGCOLOR="#FFCC00" LINK="Maroon" 
 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 ---!>
<CFOUTPUT QUERY="GetItem">
    <SCRIPT LANGUAGE="JAVASCRIPT">
    alert('A(n) #ItemName# was added to your shopping cart.')
    </SCRIPT>
</CFOUTPUT>
<!--- 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">
    <BR><BR>
    <CF_ShowDoc ID=3>
</SPAN>
<CFINCLUDE TEMPLATE="_showcart.cfm">
</BODY>
</HTML>