# LuckyNumberDB.jcx Sample

This topic inludes the source code for the LuckyNumberDB.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/lucky_number_db/

## Sample Source Code

`01 package database.lucky_number_db; 02 03 import com.bea.control.DatabaseControl; 04 import com.bea.control.ControlException; 05 import java.sql.SQLException; 06 import java.util.Iterator; 07 08 /** 09 * Defines a new database control. 10 * 11 * The @jc:connection tag indicates which WebLogic data source will be used by 12 * this database control. Please change this to suit your needs. You can see a 13 * list of available data sources by going to the WebLogic console in a browser 14 * (typically http://localhost:7001/console) and clicking Services, JDBC, 15 * Data Sources. 16 * 17 * @jc:connection data-source-jndi-name="cgSampleDataSource" 18 */ 19 public interface LuckyNumberDB extends com.bea.control.ControlExtension, DatabaseControl 20 { 21 22 /** 23 * <p>Creates the PLAYERS table with columns NAME and NUMBER.</p> 24 * 25 * <p>The PLAYERS table is created and populated when WebLogic Workshop 26 * is installed. This method is here to illustrate that CREATE TABLE, like 27 * all SQL commands, can be issued from a Database control method.</p> 28 * 29 * @jc:sql statement="CREATE TABLE PLAYERS ( NAME VARCHAR(30), NUMBER INT )" 30 * 31 * @throws java.sql.SQLException 32 */ 33 void createTable() throws SQLException; 34 35 36 /** 37 * <p>Adds a player (NAME, NUMBER) to the PLAYERS table.</p> 38 * 39 * @jc:sql statement="INSERT INTO PLAYERS (NAME, NUMBER) VALUES ({playerName},{number})" 40 * 41 * @throws java.sql.SQLException 42 */ 43 void insertPlayer(String playerName, int number) throws SQLException; 44 45 /** 46 * <p>Returns an Iterator containing a PlayerRecord for each player in the PLAYERS table.</p> 47 * 48 * <p>Note that in the Alpha release, you must not allow execution of additional 49 * queries until you are finished using the Iterator used by this method.</p> 50 * 51 * @jc:sql statement="SELECT NAME, NUMBER FROM PLAYERS ORDER BY NUMBER" 52 * iterator-element-type="database.lucky_number_db.PlayerRecord" 53 * 54 * @throws java.sql.SQLException 55 * @throws com.bea.control.ControlException 56 */ 57 Iterator getAllPlayers() throws SQLException, ControlException; 58 59 /** 60 * <p>Returns an Iterator containing a PlayerRecord for each player whose NUMBER=winningNumber.</p> 61 * 62 * <p>Note that in the Alpha release, you must not allow execution of additional 63 * queries until you are finished using the Iterator used by this method.</p> 64 * 65 * @jc:sql statement="SELECT NAME, NUMBER FROM PLAYERS WHERE NUMBER = {winningNumber} ORDER BY NAME" 66 * iterator-element-type="database.lucky_number_db.PlayerRecord" 67 * 68 * @throws java.sql.SQLException 69 * @throws com.bea.control.ControlException 70 */ 71 Iterator getAllWinners(int winningNumber) throws SQLException, ControlException; 72 73 /** 74 * <p>Deletes the PLAYERS table from the database.</p> 75 * 76 * <p>The PLAYERS table is created and populated when WebLogic Workshop 77 * is installed. This method is here to illustrate that DROP TABLE, like 78 * all SQL commands, can be issued from a Database control method.</p> 79 * 80 * @jc:sql statement="DROP TABLE PLAYERS" 81 * 82 * @throws java.sql.SQLException 83 */ 84 void destroyTable() throws SQLException; 85 86 }`