Database application development is a feature of JBuilder Professional and Enterprise. Distributed application development is a feature of JBuilder Enterprise.
The Query property editor displays when you click the ellipsis button in the value field for the query
property of a QueryDataSet
. You can use the Query property editor to set the properties of the QueryDescriptor
visually, but it also has several other uses. The Query property editor is shown below. Each of its options is explained in further detail as well.
For more information, see the com.borland.dx.sql.dataset.QueryDescriptor topic in the DataExpress Library Reference documentation.
On the Query tab, the following options are available:
Database
objects to
which this QueryDataSet
can be bound. This property must be set for the query to run successfully. To instantiate a Database
, see "Connecting to a database".
Selecting a Database
object enables the SQL Builder and Browse Tables button.
Click the SQL Builder button to display the SQL Builder. The SQL Builder provides a visual representation of the database, and allows you to create a SQL Statement by selecting Columns, adding a Where clause, an Order By clause, a Group By clause, and viewing and testing the generated SQL Statement. When you click OK, the SQL Statement you created with the SQL Builder will be placed in the SQL Statement field of the Query dialog.
Click the Browse Tables button to display the Available Tables and Columns dialog. The Available Tables and Columns dialog displays a list of tables in the specified Database
, and the columns in the selected table. The Paste Table and Paste Column buttons allow you to quickly create your query statement by pasting the name of the selected table (by clicking the Paste Table button) or selected column (by clicking the Paste Column button) into your query statement at the cursor's current (insertion) point.
This button is dimmed and unavailable while the Database field displays the value "<none>". Select a Database
object in the Database field to enable this button.
Database
specified in the Database drop-down list.
Use the Browse Tables button to quickly paste the selected table and column names into the query statement.
This is a required property; you must specify a valid SQL statement. If the SQL statement does not return a result set, an exception is generated.
An example of a simple SQL statement that is used throughout this text selects three fields from the EMPLOYEE table:
SELECT emp_no, last_name, salary FROM employee
This following SQL statement selects all fields from the same table.
SELECT * FROM employee
The Execute Query Immediately When Opened option determines whether the query executes automatically when the QueryDataSet
is opened. This option defaults to checked, which allows live data to display in the UI designer when the QueryDataSet
is bound to a data-aware component.
DataSet
rows to be performed on a separate thread. This allows the DataSet
data to be accessed and displayed as the QueryDataSet
is fetching rows from the database connection.
When Place SQL Text In Resource Bundle is checked, upon exiting the query
property editor, the Create ResourceBundle dialog displays. Select a resource bundle type. When the OK button is clicked, the SQL text is written to a resource file so that you can continue to use source code to persist SQL for some applications. See "Place SQL Text In Resource Bundle" for more description of this feature.
If unchecked, the SQL string is written to the QueryDescriptor
as a String embedded in the source code.
Database
. The result ("Success" or "Fail") is displayed in the gray area directly beneath the Test Query button.
If the area below the button indicates success, the query will run. If it indicates Fail, review the information you have entered in the query
for spelling and omission errors.
On the Parameters tab, you can select an optional ReadWriteRow
or DataSet
from which to fill in parameters, used for parameterized queries. Parameter values are specified through an instantiated ReadWriteRow
. Select the ReadWriteRow
object (or the ReadWriteRow
subclass) that contains the values for your query parameters from the drop-down list.
Any ReadWriteRow
, such as ParameterRow
, DataSet
, and DataRow
may be used as query or procedure parameters. In a ParameterRow
, columns can simply be set up with the addColumns
and setColumns
methods. DataSet
and DataRow
should only be used if they already contain the columns with the wanted data.
See "Using parameterized queries to obtain data from your database" for an example of this.
java.util.ResourceBundle
contains locale-specific objects. When your program needs a locale-specific resource, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles.
The Create ResourceBundle dialog appears when the query
editor is closing, if a SQL statement has been defined in the query
editor and the "Place SQL Text In Resource Bundle" option has been checked. The resource bundle dialog looks like this:
To use a resource bundle in your application,
ResourceBundle
. To simplify things, the JDK provides two useful subclasses of ResourceBundle
: ListResourceBundle
and PropertyResourceBundle
. The ResourceBundle
class is itself an abstract class. In order to create a concrete bundle, you need to derive from ResourceBundle
and provide concrete implementations of some functions which retrieve from whatever storage you put your resources in, such as string. You can store resources into this bundle by right-clicking a property and specifying the key. JBuilder will write the strings into the resource file in the right format depending on the type.
If you select ListResourceBundle
, a .java file will be generated and added to the project. With ListResourceBundle
, the messages (or other resources) are stored in a 2-D array in a java source file. ListResourceBundle
is again an abstract class. To create an actual bundle that can be loaded, you derive from ListResourceBundle
and implement getContents()
, which most likely will just point to a 2D array of key-object pairs. For the above example you would create a class:
package myPackage; public class myResource extends ListResourceBundle { Object[][] contents = { {"Hello_Message", "Howdy mate"} } public Object[][] getContents() { return contents; } }
If you select PropertyResourceBundle
, a properties file will be created. The PropertyResourceBundle
is a concrete class, which means you don't need to create another class in order to use it. For property resource bundles, the storage for the resources is in files with a .properties extension. When implementing a resource bundle of this form, you simply provide a properties file with the right name and store it in the same location as the class files for that package. For the above example, you would create a file myResource.properties and put it either in the CLASSPATH or in the zip/jar file, along with other classes of the myPackage package. This form of resource bundle can only store strings, and loads a lot slower than class-based implementations like ListResourceBundle
. However, they are very popular because they don't involve working with source code, and don't require a recompile. The contents of the properties file will be like this:
# comments Hello_message=Howdy mate
Click Cancel or OK:
Clicking the Cancel button (or deselecting the "Place SQL text in resource bundle" option in the query
dialog), writes a QueryDescriptor
like the following to the Frame file. The SQL text is written as a string embedded in the source code.
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, "select * from employee", null, true, LOAD.ALL));
Clicking the OK button creates a queryDescriptor
like the following:
queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, sqlRes.getString("employee"), null, true, LOAD.ALL));
Whenever you save the SQL text in the QueryDescriptor
dialog, JBuilder automatically creates a new file called "SqlRes.java". It places the text for the SQL string inside SqlRes.java and creates a unique string "tag" which it inserts into the text. For example, for the select statement "SELECT * FROM employee", as entered above, the moment the OK is pressed, the file SqlRes.java would be created, looking something like this:
public class SqlRes extends java.util.ListResourceBundle { static final Object[][] contents = { { "employee", "select * from employee" }}; static final java.util.ResourceBundle res = getBundle("untitled3.SqlRes"); public static final String getStringResource(String key) { return res.getString(key); } public Object[][] getContents() { return contents; } }
If the SQL statement is changed, the changes are saved into SqlRes.java. No changes will be necessary to the code inside jbInit()
, because the "tag" string is invariant.
For more information on resource bundles, see the JavaDoc for java.util.ResourceBundle
, found from JBuilder help by selecting Help|Java Reference. Then select the java.util
package, and the ResourceBundle
class.