The program to create and load the tables, CreateRSTables, was actually included when the Alice application (see Appendix C: About the Example Applications) was deployed, but it could not run against the database without the DataSource we added in the previous panel. After starting Cloudscape, you should be able to run it now by clicking the Go button next to "Reset the Database."
CreateRSTables is a helper class rather than a bean and uses JDBC for its task. The program first drops the "SurveyBeanTable" and SurveyNames tables from the database to remove any existing data, then creates them. Next, it loads predefined rows to give us something to work with. This is a straight JDBC application; there's nothing interesting about it from the J2EE/EJB standpoint, other than the way it retrieves a connection to the database. As shown in the code below, CreateRSTables retrieves a DataSource using a JNDI lookup for java:comp/env/jdbc/gsejbDB — remember adding that entry in The Rock Survey Database? It then obtains a connection from the DataSource:
Connection con = null;
DataSource ds = null;
InitialContext ic = null;
Statement stmt = null;
String sJNDIdbName = "java:comp/env/jdbc/gsejbDB";
try
{
ic = new InitialContext();
ds = (DataSource)ic.lookup( sJNDIdbName );
con = ds.getConnection();
stmt = con.createStatement();
}
...