UsersDBControl.jcx Sample

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

Sample Location

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

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/controls/database/

Sample Source Code


01 package controls.database;
02 
03 import java.io.Serializable;
04 import java.sql.SQLException;
05 
06 import com.bea.control.DatabaseControl;
07 
08 /**
09  * @jc:connection data-source-jndi-name="cgSampleDataSource"
10  */
11 public interface UsersDBControl extends com.bea.control.ControlExtension, DatabaseControl
12 {
13     /**
14      * @jc:sql statement="create table users (username VARCHAR(50), password VARCHAR(50))"
15      */
16     public void createUsersTable() throws SQLException;
17     
18     /**
19      * @jc:sql statement::
20      *   INSERT INTO USERS (username, password) 
21      *   VALUES ({username}, {password})
22      * ::
23      */
24     public int insertUserString username, String password );
25 
26     /**
27      * @jc:sql statement::
28      * SELECT * FROM USERS WHERE USERNAME = {username}
29      * ::
30      */
31     public User lookupUserString username );
32 
33     /**
34      * @jc:sql statement::
35      * UPDATE USERS SET USERNAME = {username}, PASSWORD = {password} WHERE USERNAME = {username}
36      * ::
37      */ 
38     public int updateUserString username, String password );
39 
40     /**
41      * @jc:sql statement::
42      * SELECT * FROM USERS
43      * ::
44      */
45     public User[] getAllUsers();
46 
47     /**
48      * @jc:sql statement::
49      * DELETE FROM USERS WHERE USERNAME = {username}
50      * ::
51      */
52     public int deleteUserString username );
53 
54 
55     public static class User implements Serializable
56     {
57         public String username;
58         public String password;
59         
60         public User()
61         {
62         }
63 
64         public UserString username, String password )
65         {
66             this.username = username;
67             this.password = password;
68         }
69     }
70 }