جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with...

24
Advanced database development using Oracle-COMP375 Week 12 Continue from Week 11 In this example, we want to continue on to the Layout wizard in order to specify how the new form will appear. Make sure the Create the block, then call the Layout wizard option is selected and click on the Finish button. The data block will be created (as can be seen in the Object Navigator in the background). The objects created include the EMPLOYEE data block containing items for each of the columns that were selected in the third step of the wizard. Once the new data block and items are created, the first dialog box in the Layout wizard will appear: Click on the Next button and the following dialog box will appear: Department of Computer Science, College of Art and Sciences, University of NIZWA

Transcript of جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with...

Page 1: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Continue from Week 11In this example, we want to continue on to the Layout wizard in order to specify how the new

form will appear. Make sure the Create the block, then call the Layout wizard option is selected

and click on the Finish button.

The data block will be created (as can be seen in the Object Navigator in the background). The

objects created include the EMPLOYEE data block containing items for each of the columns that

were selected in the third step of the wizard.

Once the new data block and items are created, the first dialog box in the Layout wizard will

appear:

Click on the Next button and the following dialog box will appear:

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 2: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

The layout for a data block may be placed on any existing canvas. In this case, there are no

existing canvases so the only option available is to create a new canvas.

Click on the Next button to display the following dialog box:

In this dialog box, the columns from a given base table on a data block can be added to the

layout. Since we are laying out the EMPLOYEE data block, it is highlighted automatically. Move

all of the Available Columns over to the Displayed Items side by clicking on the double right

arrow and click on the Next button.

In this dialog box, the field labels, field sizes and field heights can be altered. Change the field

labels as shown below and click on the Next button:

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 3: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

The following dialog box will appear:

There are two main styles for forms. A Tabular layout arranges the field labels across the top of

the form with a number of records below as in a spreadsheet.

A Form layout places the field labels to the left of the fields. Generally only one record is

displayed at a time.

For this example, choose a Form layout and click on the Next button. In the following dialog box, type a title for the frame (around the data block) and check the option

to include a scroll bar.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 4: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

The number of records displayed for a Form layout should be 1. The number of records

displayed in a Tabular layout can be more than 1.

Click on the Next button and the final dialog box for the Layout wizard will appear.

Click on the Finish button to create the layout. A new Canvas will be created with the new block

and all of the form items added in the layout wizard.

At this point the Layout Editor should appear and the new form with the data block will appear.

The Layout Editor

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 5: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

To view the actual form and its blocks and fields, pull down the Tools menu and select the

Layout Editor menu item (if it not already displayed).

In the Layout Editor, fields and labels can be moved around by clicking and dragging. Other text,

lines and boxes, etc. can be added using the tool palette on the left side of the window.

Some common operations on the Layout Editor include: Move a field or a field label by clicking and dragging the item with the left mouse button.

Change the text of a label by choosing the text tool button from the tool bar and then clicking

on a label. To stop editing the label, click anywhere outside of the label text.

Add text to the block by choosing the text tool button from the tool bar and then clicking on a

open area. Type the new text. To change the font, highlight the text, pull down the Format menu

and click on the Font menu item.

To change the text color of a label, use the pointer tool to highlight a label and then click on

the Text Color palette button to choose the color.

Change the width of a field by clicking on the field. Then drag one of the handles (small black

boxes around the field) to re-size the field.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 6: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

For example, on the employee form, you may wish to make the FNAME field wider to

accommodate longer first names.

Use the Zoom In tool to zoom in to the form (e.g., make everything appear larger). Or use

the Zoom Out tool to zoom out of the form.

Displaying PropertiesWhile in the Layout Editor, double clicking on an object will bring up that object’s properties.

Optionally, clicking on an object with the right mouse button will bring up a small menu which

has the Properties menu item on it. The following figure shows the properties for the FNAME

item.

Each type of object has a slightly different set of properties. For example, double clicking on the

EMPLOYEE data block in the Object Navigator (pull down the Tools menu and choose Object

Navigator) will display that data block’s properties.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 7: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Some properties of interest for a data block include: WHERE Clause – specify a WHERE clause to filter the selection of rows from the base

table.

ORDER BY Clause – specify an ORDER BY clause to alter the displayed order of the

records.

Delete Allowed, Insert Allowed, Query Allowed and Update Allowed – toggle these

properties to allow or prevent the action. For example, setting Delete Allowed to FALSE

prevents users from deleting records from the corresponding base table using this form.

There are numerous other properties that affect the fonts, colors, size and position of objects

in the block.

Saving, Compiling and Running Forms

Forms can be saved in files in a directory of your choosing. The “source code” for a form is

stored in a file with a .fmb extension. Compiled forms have a .fmx extension.

Under MS Windows, forms can be saved in a folder (subdirectory) on the local hard disk, on a

file server or on a USB disk (thumb drive or memory stick). It is desirable to maintain separate

subdirectories (folders) for forms associated with different projects. One significant item to be

aware of is that Oracle Forms will have difficulty running any form saved in a folder that has

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 8: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

spaces or punctuation other than the underscore character in the name. For example, it is

common in Windows to just save files in “My Documents”. However, since this has a space in

the name, the form will not run.

Therefore, if you are developing on a local machine, it is recommended that you at least make a

simple directory such as C:\forms or E:\forms if using a USB disk and save all forms files there.

Saving a FormTo save a form, pull down the File menu and select the Save menu item.

Under MS Windows, this dialog box looks like:

Note that in your company or organization, forms and other files may have to be saved in a

special directory. The above figure is simply an example.

It is critical that you do not save the file with spaces in the file name. In addition, you

should save the files in a local directory where the directory name(s) have no spaces in the

them. If you save the file in “My Documents” for example, or on the Windows desktop, you will be unable to run or test the forms. Fill in a file name in the File Name: field. Be sure it contains no spaces and that it ends with .fmb

Click on the Save button to save the file. For this example, use the file name employee.fmb

To save this form on a USB disk in the E: drive, use the file name: E:\employee.fmb

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 9: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

To enhance portability of forms across different operating systems, use file names that begin

with a letter, contain no spaces or punctuation (except for the underscore character), have all

lower case letters and are relatively short.

Compiling/Building a FormBefore a form can be executed (run), it must be Compiled and Built. Compiling runs a PL/SQL

compiler on all of the procedures and triggers in the form. Building (or compiling the file) creates

the .fmx file that is then used to run the form.

To compile a form, first make sure the form is saved. Pull down the Program menu and select

the Compile Module menu item.

If a form has errors (e.g., in the PL/SQL code, or if the database schema changes) they will be

displayed in a window as they are encountered. A record of the compilation process, including

error messages, is kept in a file with a .err extension. For example, if the form is named

employee then the record of the compilation will be stored in employee.err

Alternatively, Oracle Forms defaults to automatically compiling the form each time it is executed

(run) from the forms Builder as will be demonstrated in the next step. For more details on the

default behavior, pull down the Tools menu and check the Preferences menu item.

Running a FormAs discussed in the introduction section, Oracle Forms from version 9i and up are intended to

urn in three tier architecture. The database acts as the back-end tier. The Oracle9iAS

Containers for Java (OC4J) service acts as the middle tier and a web browser (Internet Explorer,

Firefox, Chrome, etc.) takes on the role of the user-interface tier. Oracle Forms 11g runs using

the Fusion Middleware system.

Running a Form using Oracle 9iDSUnless this environment has already been established, a local client-side OC4J service may be

used in place of the middle tier.

Before running a form, the OC4J service should be started. Use the Start Menu to navigate to:

Start -> Programs -> Oracle9i Developer Suite - Home -> Forms Developer -> Start IC4J

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 10: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Instance

A Command prompt will open (in Windows) similar to the following:

Note that by default, OC4J runs on port 8888. If this conflicts with another service or if you have

firewall software that prevents opening up such ports, you will need to change the configuration

of either OC4J, your firewall software or both.

If you receive an error when running OC4J, it may be because another OC4J instance is already

running. If you are uncertain, save your work and reboot the PC. Then run a single instance of

OC4J.

With OC4J configured and running, and the form designed and saved, it can be executed. To

run the form, pull down the Program menu and select the Run Form menu item. This will launch

your default web browser which will then connect to OC4J (port 8888) on the local machine.

Oracle’s JInitiator will load and the form should appear.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 11: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Use the various menus and items to query the form, enter new data and save new and changed

data. Please read the section below on Query By Example to see how to query data from the

underlying tables and populate the fields in the form.

If OC4J service is not running, an error message similar to the following will be displayed:

If you see error FRM-10142, make sure the OC4J Instance is running. Look in the Windows

Start Menu folder where you started Forms Builder. There should be a menu item called: Start

OC4J Instance. Run that program (a DOS box will appear) and make sure it looks similar to the

example above. If the OC4J Instance gives errors, it may be because your computer has a

personal firewall (such as that included in Windows XP Service Pack 2). Make certain you

configure your personal firewall to allow local connections to port 8888.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 12: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

If you have previously not installed the latest JInitiator, your browser will launch with the

following message:

Click on the “Get the Plug-in” button and follow the instructions to install it. Note that the jinit.exe

file is actually installed with Oracle9i Developer Suite.

Reminder: If you saved your form in a folder that has spaces in the name, or if your file name

has spaces, the form will not load in the web browser. In such cases, you may see error: FRM-

90928 Positional parameter after key on command line. If this occurs, simply use the “Save As”

item on the File menu to save the form under a new name with no spaces. Then try to run the

form again.

Technical Notes and Possible Errors: The height and width settings for the Java applet that displays the forms are set in the

formsweb.cfg file located in \forms90\server directory under the Oracle9iDS installation

home. Edit the formsweb.cfg file with a text editor and scroll down to Section 3) Values for

the Forms applet parameters:

Change the width= and height= parameters accordingly and save the file. You may need

to restart the OC4J server. Note that you can also set the width and height parameters to

percentages. For example setting width=100% will cause the applet to use up the entire

width of the web browser.

Error FRM-18125: Could not find the web browser appears if you do not have a web

browser installed or your web browser is not found in the PATH. If you are certain you

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 13: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

have a web browser installed, set its location in the Preferences section in the Forms

builder (Edit -> Preferences -> Runtime tab).

Error FRM-10142: The HTTP listener is not running on… appears if the OC4J is not

running. Start the OC4J Instance.

Running Oracle Forms 11gThe process for running Oracle Forms using the 11g version is slightly different. Oracle Forms

11g requires an instance of Oracle Fusion Middleware / Weblogic Server to be running on the

deployment machine. For developers this is typically the same computer they are using to run

Forms Builder. During the installation of the Oracle Fusion Middleware / Weblogic Server, one or

more Domains will be created. For example, the default name for the Oracle Forms and Reports

domain will be ClassicDomain. The following assumes this default domain name is in use.

It is important to note that you can only run one Admin server at a time, so if the Admin sever for

the Weblogic Server’s domain is running, it must be shut down before the Admin server for the

ClassicDomain can be started (The classic error here from Java is “unable to obtain lock”).

Make sure the Admin Server for the ClassicDomain is running by Start Admin Server menu item

as shown below:

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 14: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

When you run a form for the first time under the Weblogic Server, your form will be deployed in

that server instance and made available on the default server port. During the default

configuration that port is usually set to 7003 so your web browser will point to the Weblogic

Server (which may be running on your local PC) at port 7004 and will request the

/forms/frmservlet resource. The full URL will look like: http://127.0.0.1:7003/forms/frmservlet

Where 127.0.0.1 is the localhost IP address.

Oracle Forms 11g is also picky about the Java Runtime connected with your browser. It may

request that a different version is used in order to display the running form. In my case I had JRE

1.7 installed but the forms servlet requested I install version 1.6.

There are dozens of other configuration steps to consider here and based on my research it

seems many people have difficulties getting Weblogic Server and the appropriate Oracle Forms

versions to talk to one another. So some patience will definitely be required. Below is an

example of an oracle 11g Form running in a web browser.

Query By ExampleWhen a Developer Form is first executed, no records will appear. That is, the blank form will

appear with no data in the fields. This is similar to running a word processor where the opening

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 15: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

screen is blank. From this blank or empty form, the user can immediately begin to enter new

data records by simply typing them in.

However, in many cases, the user would first like to see if there are any records in the database.

To do this, the user must query the database using the query capabilities that are built into every

Oracle form. This will bring a copy of the records from the database into the form.

When a tool such as SQL*Plus is used, the user must form the SQL query by typing it directly in.

In the case of embedded SQL, the SQL statements are programmed into the host language

(such as “C” or Java) and automatically executed for the user. In the case of Oracle Forms,

complex queries can be formulated and submitted to the database using a technique called

Query By Example or QBE. In QBE, the name of the table or tables is fixed as are the names of

the columns that will be returned from the tables. The user can supply their own criteria by

supplying values for the fields. These values become part of the query that is submitted to the

database on behalf of the user.

Querying a form in Oracle Forms is a two step process. Clicking on the Query button or

choosing Enter Query from the Query menu places the form in Enter Query mode. In enter query

mode, the form is cleared and the user can navigate in the various fields. Example values can

be supplied as criteria for the query. For example, a user looking for all employees in the

RESEARCH department might type a “5″ in the DNO field while in enter query mode.

Clicking on the Query button a second time (or pulling down the Query menu and choosing

Execute Query) executes the current query using any supplied data as criteria in a WHERE

clause. If no criteria are supplied, then all records in the table will be displayed. Continuing the

above example, supplying a “5″ for the DNO field while in enter query mode would cause the

following SQL query to be submitted to the database:

SELECT fname, lname, ssn, bdate, salary, dno FROM employee WHERE dno = 5;

Most of the commands on the menus and on the button bar can also be activated using special

key combinations or function keys. For example, within the Java based forms display pressing

the F11 function key places the form in Enter Query mode. Pressing the CTRL+F11 function key

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 16: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

executes a query. (Note: Please check the Help menu to see if the keys in your system are the

same). To see a list of keys and their functions, pull down the Help menu and choose the Keys

option.

Once data has been queried, it is retrieved from the database and stored in a buffer in the

associated data block on the form. This means that a local copy of the data now exists in the

client’s memory. Appropriate locks are placed on the data so that the client maintains a

consistent view of the data in the associated tables.

The user can navigate through the data in a block by pressing the up and down arrow keys to

scroll between records. To change data in a form, the user can TAB to the field of interest, and

type over the existing data.

To enter new data into the form, the user can scroll to the last record and then down once more

to move to a blank record. Data can then be typed into the fields and the TAB key can be

pressed to move between fields on the form.

To save both changed and new records on a form, pull down the Action menu and choose the

Save menu item. Any records that have been changed are collected and submitted to the

database as SQL UPDATE statements. Any new records are collected and submitted to the

database as INSERT statements. These statements are submitted as a single logical unit of

work. Thus if a failure occurs during any of the statements, the entire transaction will be rolled

back.

If the user attempts to clear the block or exit the form and there are some changes that have not

yet been applied to the database, they will be prompted to commit the changes before exiting or

clearing the form. The block is cleared when the Enter Query mode is invoked. A block can also

be cleared using the Clear Block and Clear Form menu items.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 17: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

To exit from a running form, pull down the Action menu and select the Exit menu item. Warning: Do not simply close the web browser as this will leave a Java Applet process running and this will lock your form (.fmx file).As a review, here are a few basic functions that can be performed by default in any Form:

Forms function

Notes

Querying a

form

To see all records in the table, simply “Execute Query” (via Query menu or by

pressing F8 in Windows).

To filter the record, “enter query” mode, specify the query parameters in the fields

and then “Execute Query”.

Inserting new

records

Scroll to the last record and then scroll once more to get a blank record. Type in

data for each field and then commit these changes by pulling down the Action

menu and choose the Save menu item.

For master/detail forms (discussed below) first either query a master record or

insert and save a master record (in the master data block), then navigate to the

detail block and insert new records there.

Updating

existing

records

Query the database and scroll to the record of interest. Change the values in the

fields and then save the changes.

For master/detail forms, changes to the key in the master block may be prevented

if detail records exist (thus insuring relational integrity).

Deleting

records

Query the database and scroll to the record of interest. Pull down the Records

menu and choose Delete record. Then save the changes.

For master/detail forms, attempting to delete a master record when detail records

exist typically results in an error. In such cases, all of the detail records should be

deleted first and then the master record should be able to be deleted.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 18: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Exiting the

Form

Pull down the Action menu and choose the Exit menu item. Existing in this way

will release any Java processes that might lock up your forms files.

Creating a Single Block FormFor this exercise, create a simple data entry form for the DEPARTMENT table with the following

characteristics:

Select and display all of the columns in the DEPARTMENT table.

In the layout wizard, use the Tabular layout and display 5 Records in the form. Add a scrollbar.

In the Layout Editor, make the DNAME field a bit wider to accommodate longer department

names.

Change the Properties of the DEPARTMENT block so that that data is ORDER BY DNAME.

Save the form under the file name: depart.fmb

The resulting form should look like the following:

Use the enter query mode and execute query functions to query the department table for a

specific department name and/or number.

Department of Computer Science, College of Art and Sciences, University of NIZWA

Page 19: جامعة نزوى · Web viewOracle Forms 11g is also picky about the Java Runtime connected with your browser. It may request that a different version is used in order to display

Advanced database development using Oracle-COMP375Week 12

Department of Computer Science, College of Art and Sciences, University of NIZWA