# ItemsDBControl.jcx Sample

This topic inludes the source code for the ItemsDBControl.jcx Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebServices/database/dynamicSQL/

## Sample Source Code

`01 package database.dynamicSQL; 02 03 import com.bea.control.*; 04 import java.sql.SQLException; 05 06 /** 07 * Defines a new database control. 08 * 09 * The @jc:connection tag indicates which WebLogic data source will be used by 10 * this database control. Please change this to suit your needs. You can see a 11 * list of available data sources by going to the WebLogic console in a browser 12 * (typically http://localhost:7001/console) and clicking Services, JDBC, 13 * Data Sources. 14 * 15 * @jc:connection data-source-jndi-name="cgSampleDataSource" 16 */ 17 public interface ItemsDBControl extends DatabaseControl, com.bea.control.ControlExtension 18 { 19 // Add "throws SQLException" to request that SQLExeptions be thrown on errors. 20 21 static public class ItemRecord 22 { 23 public int ItemNumber; 24 public String ItemName; 25 public int QuantityAvailable; 26 public double Price; 27 } 28 29 static final long serialVersionUID = 1L; 30 31 /** 32 * This method accepts a whole SQL query as a substition parameter. 33 * 34 * @jc:sql statement="{sql: query}" 35 */ 36 ItemRecord[] dynamicStatement(String query); 37 38 /** 39 * This method accepts a SQL WHERE phrase as a substitution parameter. 40 * 41 * @jc:sql statement="SELECT * FROM WEBLOGIC.ITEMS {sql: whereClause}" 42 */ 43 ItemRecord dynamicWhereClause(String whereClause); 44 45 /** 46 * In this method, the {sql: } substitution syntax is not necessary, since an individual 47 * value is being substituted into a WHERE clause. 48 * 49 * @jc:sql statement="SELECT * FROM WEBLOGIC.ITEMS WHERE ITEMNUMBER = {whereValue}" 50 */ 51 ItemRecord simpleSubstitutionWhere(int whereValue); 52 53 /** 54 * This method accepts a SQL LIKE clause as a substitution parameter. 55 * 56 * @jc:sql statement="SELECT * FROM WEBLOGIC.ITEMS WHERE ITEMNAME {sql: likeClause}" 57 */ 58 ItemRecord[] dynamicLikeClause(String likeClause); 59 60 /** 61 * In this method, the {sql: } substitution syntax is not necessary, since an individual 62 * value is being substituted into a LIKE clause. 63 * 64 * Note that single quotes are added to the substituded value. 65 * 66 * The final SQL statement passed to the database is: 67 * SELECT * FROM WEBLOGIC.ITEMS WHERE ITEMNAME LIKE '%CYCLE%' 68 * 69 * @jc:sql statement="SELECT * FROM WEBLOGIC.ITEMS WHERE ITEMNAME LIKE {likeValue}" 70 */ 71 ItemRecord[] simpleSubstitutionLike(String likeValue); 72 73 74 }`