Database application development is a feature of JBuilder Professional and Enterprise. Distributed application development is a feature of JBuilder Enterprise.
The JBuilder IDE provides tools that can help you quickly create applications that query a database. The Data Modeler can build data modules that encapsulate a connection to a database and the queries to be run against the database. The Data Module Application wizard can then use that data module to create a client-server database application.
To begin a new project,
For more specific information about creating projects, see the online help topic "Creating and managing projects."
To display the Data Modeler,
To open an existing Java data module in the Data Modeler,
To begin building an SQL query, you must first open a connection URL. There are several ways you can do this:
To view the tables, double-click the Tables node or choose the Tables expand icon.
From the list of tables, select the table you want to query and double-click it. Double-click the Columns node to view all the columns in the selected table.
The SELECT statement is the data retrieval statement that returns a variable number of rows of a fixed number of columns. The Data Modeler helps you build the SELECT statement.
Click the Copy button.
The name of the selected column appears in the Selected Columns box and the table name appears in the Queries panel at the top. Continue selecting columns until you have all you want from that table. If you want to select all columns, click the Copy All button.
Aggregate functions provide a summary value based on a set of values. Aggregate functions include SUM, AVG, MIN, MAX, and COUNT. To add an aggregate function to the query,
Click the column whose data values you want aggregated in the Available Columns list.
Click the function you want to use on that column from the Aggregate Functions column.
If you want the function to operate on only unique values of the selected column, check the Distinct check box.
Choose Add Aggregate to add the function to your query.
As you select columns and add functions, your SQL SELECT statement is being built. When you aggregate data, you must include a GROUP BY clause. For information on GROUP BY clauses, see "Adding a GROUP BY clause". To view it, click the SQL tab.
The GROUP BY clause is used to group data returned by a select statement and is often used in conjunction with aggregate functions. When used with aggregate functions, the following process is followed:
To add a Group By clause to your query, click the Group By tab to display the Group By page.
The Available Columns box lists the columns of the currently selected query in the Queries panel of the Data Modeler. The Group By box contains the column names the query will be grouped by. By default, the query is not grouped by any column until you specify one.
To add a Group By clause to your query,
A Group By clause is then added to your SQL SELECT statement. To view it, click the SQL tab.
To add the DISTINCT keyword, check the Distinct option on the Columns page.
The Columns list on the left contains the columns of tables in the currently selected query in the Queries panel of the Data Modeler. Use the Columns, Operators, and Functions lists to build the clause of the query in the Where Clause box.
To transfer a column as a column name to the Where Clause box, select a column in the Columns list and click the Paste Column button.
To transfer a column as a parameter as in a parameterized query, select a column in the Columns list and click the Paste Parameter button.
Select the operator you need in the Operators drop-down list and click the Paste button. Every Where clause requires at least one operator.
If your query requires a function, select the function you need in the Functions drop-down list and click the Paste button.
By pasting selections, you are building a Where clause. You can also directly edit the text in the Where Clause box to complete your query. For example, suppose you are building a Where clause like this:
WHERE COUNTRY='USA'
You would select and paste the COUNTRY column and the = operator. To complete the query, you would type in the data value directly, which in this case is 'USA'.
When you are satisfied with your Where clause, click the Apply button. The Where clause is added to the entire SQL SELECT statement. To view it, click the SQL tab.
Select the column you want the query sorted by in the Available Columns box and click the button with the > symbol on it to transfer that column to the Order By box.
The Ascending option sorts the specified column from the smallest value to the greatest, while the Descending option sorts the specified column from the greatest value to the smallest. For example, if the sort column is alphabetical, Ascending sorts the column in alphabetical order and Descending sorts it in reverse alphabetical order.
You can sort the query by multiple columns by transferring more than one column to the Order By box. Select the primary sort column first, then select the second, and so on. For example, if your query includes a Country column and a Customer column and you want to see all the customers from one country together in your query, you would first transfer the Country column to the Order By box, then transfer the Customer column.
To view the SELECT statement, click the SQL tab. To edit it, make your changes directly in the SELECT statement.
To see the results of the query you are building,
If your query is a parameterized query, a Specify Parameters dialog box appears so you may enter the values for each parameter. When you choose OK, the query executes and you can see the results. The values you entered are not saved in the data module.
Choose Queries|Link.
In the Queries panel, click-and-drag the mouse pointer from the query you want to be the master query to the one you want to be the detail query.
Select a query to be the detail query in the Detail Query list.
The Master Query and Detail Query fields are filled with suggested fields. If they are not the ones you want, make the necessary changes.
Use the table to visually specify the columns that link the master and detail queries together:
Click the first row under the detail query column of the table to display a drop-down list of all columns that are of the same data type and size as the currently selected master column. Select the appropriate column, thereby linking the master and the detail tables together.
Choose OK.
When the Link Queries dialog box closes, an arrow is shown between the two queries in the Queries panel showing the relationship between them.
For more information about master-detail relationships, see "Establishing a master-detail relationship".
Exit the Data Modeler.
The resulting file appears in your project.
Compile the data module.
Double-click the file in the project pane to open it in the content pane to view the code the Data Modeler generated.
To display the Data Moduler Application wizard, select the Data Module Application wizard icon in the object gallery:
The wizard creates a database application for you. The wizard generates several JAVA files and an HTML file.
The files that make up the client are contained in a client2tier package:
ClientAboutBoxDialog.java - Implements the client Help About dialog.
ClientFrame.java - The client application frame that is the container for the default client user interface. Implements the application menu bar.
ClientResources.java - Contains client application strings for localization.
<datamodule>TwoTierApp.java - the application
<datamodule>AppGenFileList.html - list of files generated with a brief description of each.
setModule()
method that identifies the data module. The setModule()
method the wizard creates calls the frame's jbInit()
method. The wizard also removes the call to jbInit()
from the frame's constructor.
In the source code of your application file, call the frame's setModule()
method, passing it the data module class.
For example, suppose you have used the Data Modeler to create a data module called CountryDataModelModule
. To access the logic stored in that data module in an application you write, you must add a setModule()
method to your frame class.
To add the setModule()
method and remove the jbInit()
method from the frame's constructor,
The resulting code of the frame would look like this:
package com.borland.samples.dx.myapplication; import java.awt.*; import java.awt.event.*; import javax.swing.*; //imports package where data module is import com.borland.samples.dx.datamodule.*; public class Frame1 extends JFrame { BorderLayout borderLayout1 = new BorderLayout(); CountryDataModelModule countryDataModelModule1; //Construct the frame without calling jbInit() public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); } //Component initialization private void jbInit() throws Exception { this.getContentPane().setLayout(borderLayout1); this.setSize(new Dimension(400, 300)); this.setTitle("Frame Title"); } //Overridden so we can exit on System Close protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if(e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } // The Use Data Module wizard added this code public void setModule(CountryDataModelModule countryDataModelModule1) { this.countryDataModelModule1 = countryDataModelModule1; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } }
Note that the frame's jbInit()
method is now called after the module is set and not in the frame's constructor.
Next you must call the new setModule()
method from the main source code of your application. In the constructor of the application, call setModule()
, passing it the data module class. The code of the main application would look like this:
package com.borland.samples.dx.myapplication; import javax.swing.UIManager; public class Application1 { boolean packFrame = false; //Construct the application public Application1() { Frame1 frame = new Frame1();// This is the line of code that you add frame.setModule(new untitled3.CountryDataModelModule()); //Validate frames that have preset sizes //Pack frames that have useful preferred size info, e.g. from their layout if (packFrame) frame.pack(); else frame.validate(); frame.setVisible(true); } //Main method public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch(Exception e) { } new Application1(); } }