|
[Exercise | API Docs | Short Course| Exercises] Help is available for each task. Task 1Given the following ConnectJ.properties file: #PropertiesResourceBundle for Connection Properties CSDriver=COM.cloudscape.core.RmiJdbcDriver CSURL=jdbc:cloudscape:rmi:jGuru Set up String variables to access the keys and to hold the returned values. Also set up Strings 1) containing the name of the properties file - ConnectJ, and 2) containing a SELECT statement to get all columns and rows, but omit the table name, which will be obtained and appended later in the program. Insert the following code:
Task 2Access the ResourceBundle and retrieve the driver name and databaseURL.
rbConnect = ResourceBundle.getBundle( srbName );
sDriver = rbConnect.getString( sDriverKey );
sURL = rbConnect.getString( sURLKey );
Task 3Display a GUI form which requests a userID,password and table name, has a "Connect" button and a textarea. This is done for you. When the button is clicked, in actionPerformed(), verify that a table name was entered ( from jtTable, ) get the userID ( from jtUserID ) and password ( from jpfPassword ) keyed, reset the text area ( jta ) and invoke doConnect().
Task 4In doConnect(), the driver is loaded, a Connection obtained and a Statement created as before. Your job: concatenate the query string and table name, then execute the query.
rs = stmt.executeQuery( sQuery + sTable );
Task 5In doConnect(), a boolean, a StringBuffer and a while( rs.next() loop are provided. Inside the loop, an if( bFirst ) section to determine the first time through the loop is set up. Your job: use ResultSetMetadata to get and display ColumnCount number of ColumnLabels in a single String in the text area jta. Reset the StringBuffer and ensure that this process only happens once per while loop.
Task 6In doConnect(), on every pass of the while loop, obtain ColumnCount number of columns for the row using ResultSet.getObject() and concatenate these into a single String. getObject(), as used here, will obtain a String from virtually any type returned from the database. Append the resulting String to the text area jta and reset the StringBuffer.
Copyright 1996-2000 jGuru.com. All Rights Reserved. | ||||||||||||||
|
| ||||||||||||