Developing Database Applications
Total Page:16
File Type:pdf, Size:1020Kb
Developing Database Applications JBuilder® 2005 Borland Software Corporation 100 Enterprise Way Scotts Valley, California 95066-3249 www.borland.com Refer to the file deploy.html located in the redist directory of your JBuilder product for a complete list of files that you can distribute in accordance with the JBuilder License Statement and Limited Warranty. Borland Software Corporation may have patents and/or pending patent applications covering subject matter in this document. Please refer to the product CD or the About dialog box for the list of applicable patents. The furnishing of this document does not give you any license to these patents. COPYRIGHT © 1997–2004 Borland Software Corporation. All rights reserved. All Borland brand and product names are trademarks or registered trademarks of Borland Software Corporation in the United States and other countries. All other marks are the property of their respective owners. For third-party conditions and disclaimers, see the Release Notes on your JBuilder product CD. Printed in the U.S.A. JB2005database 10E13R0804 0405060708-987654321 PDF Contents Chapter 1 Chapter 4 Introduction 1 Connecting to a database 27 Chapter summaries . 2 Connecting to databases . 28 Database tutorials. 3 Adding a Database component to your Database samples . 3 application . 28 Related documentation . 4 Setting Database connection properties . 29 Documentation conventions . 6 Setting up JDataStore . 31 Developer support and resources. 7 Setting up InterBase and InterClient. 31 Contacting Borland Developer Support . 7 Using InterBase and InterClient with JBuilder . 32 Online resources. 7 Tips on using sample InterBase tables . 32 World Wide Web . 8 Adding a JDBC driver to JBuilder . 33 Borland newsgroups . 8 Creating the .library and .config files . 33 Usenet newsgroups . 8 Adding the JDBC driver to projects. 34 Reporting bugs . 8 Connecting to a database using InterClient JDBC drivers . 35 Chapter 2 Using the Database component in your Understanding JBuilder database application . 37 applications 11 Prompting for user name and password . 38 Pooling JDBC connections . 38 Database application architecture . 11 Optimizing performance of JConnectionPool. 40 DataExpress components . 12 Logging output . 40 Key features and benefits . 13 Pooling example . 40 Overview of the DataExpress components . 14 Troubleshooting JDataStore and InterBase DataExpress for EJB components . 17 connections . 43 InternetBeans Express . 17 Common connection error messages . 43 XML database components. 17 dbSwing. 17 Chapter 5 Data modules and the Data Modeler . 18 Database Pilot . 18 Retrieving data from a data source 45 JDBC Monitor . 19 Querying a database . 46 JDataStore and JBuilder . 19 Setting properties in the query dialog box . 47 When to use JDataStore versus JDBC drivers . 19 The Query page . 47 Additional advantages of a JDataStore . 20 The Parameters page . 48 Using the JDataStore Explorer . 20 Place SQL text in resource bundle . 49 JDataStore explorer operations . 21 Querying a database: Hints & tips . 51 InterBase and JBuilder . 21 Enhancing data set performance . 51 Persisting query metadata. 52 Chapter 3 Opening and closing data sets . 52 Importing and exporting data Ensuring that a query is updatable . 52 Using parameterized queries to obtain data from a text file 23 from your database. 53 Adding columns to a TableDataSet in the editor . 23 Parameterizing a query. 53 Importing formatted data from a text file . 24 Creating the application . 53 Retrieving data from a JDBC data source . 24 Adding a Parameter Row . 54 Exporting data . 25 Adding a QueryDataSet . 54 Exporting data from a QueryDataSet to a Add the UI components . 55 text file . 25 Parameterized queries: Hints & tips . 57 Saving changes from a TableDataSet to a Using parameters . 57 SQL table. 25 Re-executing the parameterized query Saving changes loaded from a with new parameters. 59 TextDataFile to a JDBC data source . 26 Parameterized queries in master-detail relationships . 59 i Chapter 6 Coding stored procedures to handle data Using stored procedures 61 resolution . .81 Saving changes with a ProcedureResolver . .81 Stored procedures: hints & tips. 62 Example: Using InterBase stored Escape sequences, SQL statements, and procedures with return parameters . .83 server-specific procedure calls . 62 Resolving data from multiple tables . .83 Using vendor-specific stored procedures. 63 Considerations for the type of linkage Using JDataStore stored procedures and between tables in the query . .84 user-defined functions . 63 Table and column references (aliases) in a Using InterBase stored procedures . 63 query string . .84 Using parameters with Oracle PL/SQL stored Controlling the setting of the column properties . .85 procedures. 64 What if a table is not updatable? . .85 Using Sybase stored procedures . 65 How can the user specify that a table Sample application with database-server should never be updated? . .85 specific stored procedures. 65 Using DataSets with RMI (streamable data sets) . .85 Writing a custom data provider . 65 Example: Using streamable data sets . .85 Obtaining metadata . 66 Using streamable DataSet methods . .86 Invoking initData . 66 Customizing the default resolver logic. .87 Obtaining actual data . 67 Understanding default resolving . .87 Tips on designing a custom data provider . 67 Adding a QueryResolver component . .87 Understanding the provideData() method Intercepting resolver events. .88 in master-detail data sets. 67 Using resolver events . .89 Chapter 7 Writing a custom data resolver. .90 Handling resolver errors . .90 Working with columns 69 Resolving master-detail relationships. .91 Understanding Column properties and metadata . 69 Non-metadata Column properties. 69 Chapter 9 Viewing column information in the column Establishing a master-detail designer . 70 Generate RowIterator Class button . 71 relationship 93 Using the column designer to persist Defining a master-detail relationship . .94 metadata. 71 Creating an application with a master-detail Making metadata dynamic using the relationship . .94 column designer . 72 Fetching details . .97 Viewing column information in the Fetching all details at once. .97 Database Pilot . 72 Fetching selected detail records on demand. .97 Optimizing a query . 73 Editing data in master-detail data sets . .98 Setting column properties . 73 Steps to creating a master-detail relationship . .99 Setting Column properties using Saving changes in a master-detail relationship . 100 JBuilder’s visual design tools . 73 Resolving master-detail data sets to a Setting properties in code . 73 JDBC data source . 100 Persistent columns . 73 Combining live metadata with persistent Chapter 10 columns . 74 Using data modules to simplify Removing persistent columns . 74 data access 103 Using persistent columns to add empty Creating a data module using the design tools . 104 columns to a DataSet. 75 Create the data module with the wizard . 104 Controlling column order in a DataSet . 75 Add data components to the data module . 104 Adding business logic to the data module . 106 Chapter 8 Using a data module . 106 Saving changes back to your data Adding a required library to a project . 106 source 77 Referencing a data module in your Saving changes from a QueryDataSet . 78 application . 107 Adding a button to save changes from a Understanding the Use DataModule QueryDataSet . 79 wizard . 108 Saving changes back to your data source with Creating data modules using the Data Modeler. 109 a stored procedure . 80 Creating queries with the Data Modeler . 109 Saving changes using a QueryResolver . 80 Opening a URL . 110 Beginning a query. 110 ii Adding a Group By clause . 112 Data type dependent patterns . 150 Selecting rows with unique column values . 113 Patterns for numeric data . 150 Adding a Where clause. 113 Patterns for date and time data . 150 Adding an Order By clause . 114 Patterns for string data . 151 Editing the query directly . 114 Patterns for boolean data . 152 Testing your query . 114 Presenting an alternate view of the data . 152 Building multiple queries . 115 Ensuring data persistence . 153 Specifying a master-detail relationship . 115 Making columns persistent . 154 Saving your queries . 116 Using variant data types . 155 Generating database applications . 117 Storing Java objects . 155 Using a generated data module in your code . 118 Chapter 13 Using other controls and events 157 Chapter 11 Synchronizing visual components . 157 Filtering, sorting, and locating data 121 Accessing data and model information from a Retrieving data for the examples . 122 UI component . 158 Filtering data . 124 Displaying status information . 158 Adding and removing filters . 124 Building an application with a Sorting data . 127 JdbStatusLabel component . 158 Sorting data in a JdbTable . 127 Running the JdbStatusLabel application . 159 Sorting data using the JBuilder visual Handling errors and exceptions . 159 design tools . 128 Overriding default DataSetException Understanding sorting and indexing . 129 handling on controls . 160 Sorting data in code . 130 Locating data . 130 Chapter 14 Locating data with a JdbNavField . 130 Creating a distributed database Locating data programmatically . 132 application using DataSetData 161 Locating data using a DataRow . 133 Understanding the sample distributed database Working with locate options . 133 application (using Java RMI and DataSetData) . 161 Locates that handle any data type. 134.