In this step you add a database control to the Investigate Java control. The database control provides access to a database containing bankruptcy and other information about credit applicants.
The database control you add is a pre-built control provided by WebLogic Workshop. Pre-built controls act as interfaces to common data resources, such as databases, web services, Java Message Services, and Enterprise Java Beans. Pre-built controls free you from having to design a new interface each time you want to connect to one of these kinds of resources.
The tasks in this step are:
The Record class is a Java object that represents an individual record within a database. In particular, it represents an individual record of the BANKRUPTCIES table. In the following tasks you will create a database control file that queries the BANKRUPTCIES table and then returns a Record object containing the results of the query.
package investigateJCS; public class Record { static final long serialVersionUID = 1L; public String firstname; public String lastname; public String taxID; public boolean currentlyBankrupt; }
To Create a Database Control File
In this task you will create a database control file, called BankrupctiesDatabase.jcx. "JCX" stands for "Java Control Extension". A JCX file extends one of Workshop's pre-built control classes, in this case the com.bea.control.DatabaseControl class, which allows easy access to a database.
In this task, you will add a method to the database control file. This method will ultimately be able to query a database and return a Record object containing the results of the query.
To Associate a SQL Query with the Method
In this task you will associate a SQL query with the checkForBankruptcies method, so that when the method is invoked, it will query the BANKRUPTCIES table. The results of the query will be returned by the method as a return value.
SELECT TAXID, FIRSTNAME, LASTNAME, CURRENTLYBANKRUPT FROM BANKRUPTCIES WHERE TAXID={taxID}Enter into the Java pane...
public Record checkForBankruptcies(String taxID)
To Edit the Investigate Java Control to Incorporate the Database Control File
In this task you will modify the Investigate Java control to use the database control. You will edit the method requestCreditReport to invoke the database control method checkForBankruptcies. The data returned by the checkForBankruptcies method will be stored in the member variable m_currentApplicant.
public void requestCreditReport(String taxID) {/* * Assemble a credit-worthiness report on the applicant. */ // m_currentApplicant.taxID = taxID; // m_currentApplicant.firstName = "unknown"; // m_currentApplicant.lastName = "unknown"; // m_currentApplicant.approvalLevel = "unknown"; // m_currentApplicant.message = "There was insufficient data available to assemble a full report on this applicant."; /* * Send the credit-worthiness report to the client via a callback. */ // callback.onCreditReportDone(m_currentApplicant);m_currentApplicant.taxID = taxID; /* * Retrieve data from the database and store it in the rec object. */ Record rec = bankruptciesDB.checkForBankruptcies(taxID); /* * If the database returns substantial data, then store that data * in the m_currentApplicant object. */ if(rec != null) { m_currentApplicant.firstName = rec.firstname; m_currentApplicant.lastName = rec.lastname; m_currentApplicant.currentlyBankrupt = rec.currentlyBankrupt; /* * Send the credit report to the client via a callback. */ callback.onCreditReportDone(m_currentApplicant); } /* * If the database does not return substantial data, notify the client * that there is a problem. */ else { m_currentApplicant.message = "No data could be found on the applicant. Please call (555) 555-5555 for assistance. "; /* * Send the the error message to the client via a callback. */ callback.onCreditReportDone(m_currentApplicant); } }
To Test the Web Service Using the Debugger
Next you will test your Java control using the debugger. The debugger allows you to set breakpoints in your code and track how your code is running line-by-line. Setting a breakpoint in your code will cause the Java Virtual Machine to halt execution of your code immediately before the breakpoint, allowing you to step through your code beginning at that point.
Click one of the following arrows to navigate through the tutorial: