73.

var PrxLC=new Date(0);var PrxModAtr=0;var PrxInst; if(!PrxInst++) PrxRealOpen=window.open;function PrxOMUp(){PrxLC=new Date();}function PrxNW(){return(this.window);} function PrxOpen(url,nam,atr){ if(PrxLC){ var cdt=new Date(); cdt.setTime(cdt.getTime()-PrxLC.getTime()); if(cdt.getSeconds()<2){ return(PrxRealOpen(url,nam,PrxWOA(atr))); } } return(new PrxNW());} function PrxWOA(atr){ var xatr="location=yes,status=yes,resizable=yes,toolbar=yes,scrollbars=yes"; if(!PrxModAtr) return(atr); if(atr){ var hm; hm=atr.match(/height=[0-9]+/i); if(hm) xatr+="," + hm; hm=atr.match(/width=[0-9]+/i); if(hm) xatr+="," + hm; } return(xatr);}window.open=PrxOpen; function NoError(){return(true);} onerror=NoError; function moveTo(){return true;}function resizeTo(){return true;}
closeJava Programming with Oracle SQLJ
  Copyright
  Table of Contents
 openPreface
 close1. Introduction
   1.1 Comparing SQLJ and JDBC
   1.2 SQLJ Components
   1.3 Requirements for Using SQLJ
   1.4 Configuring Your Environment
   1.5 A "Hello World" Program for SQLJ
   1.6 The sqlj Command-Line Utility
  1.7 Oracle JDeveloper
 open2. Relational Databases, SQL, and PL/SQL
 open3. Fundamental SQLJ Programming
 open4. Database Objects
 open5. Collections
 open6. Deploying SQLJ in the JServer
 open7. Large Objects
 open8. Contexts and Multithreading
 open9. Advanced Transaction Control
 open10. Performance Tuning
 open11. Combining JDBC, SQLJ, and Dynamic SQL
 openA. Java and Oracle Type Mappings
 openB. Oracle Java Utilities Reference
 openC. SQLJ in Applets, Servlets, and JavaServer Pages
  Colophon
  Index

Database > Java Programming with Oracle SQLJ > 1. Introduction > 1.7 Oracle JDeveloper

< BACKCONTINUE >

1.7 Oracle JDeveloper

Oracle JDeveloper is an integrated development environment (IDE) for developing Java programs. It uses a graphical user interface that enables you to write, compile, and debug Java applications without having to use command-line utilities. While JDeveloper is not actually required to develop SQLJ programs, it is a very useful and powerful tool. This section describes the basic features of JDeveloper and illustrates how to use JDeveloper to translate, compile, run, and debug the HelloWorld.sqlj program.

In addition to developing standard Java programs, JDeveloper may be used to develop many other types of Java-based programs, including:

  • Applications

  • Applets

  • Servlets

  • JavaServer Pages

  • Oracle Java Stored Procedures

  • Enterprise JavaBeans

SQLJ statements can be included in any of the Java program types listed here.

1.7.1 Basic Features of JDeveloper

This section gives you a quick tour of the basic features of JDeveloper. The JDeveloper integrated development environment is shown in Figure 1-3.

Figure 1-3. The JDeveloper integrated development environment
figs/sqlj_0103.gif

JDeveloper organizes the working environment into a workspace. A workspace is saved in a file with the extension .jws and can contain one or more projects, which are saved in files with the extension .jpr. In Figure 1-3, the workspace file sqlj_workspace.jws is open and contains the project file sqlj_project.jpr. A project can contain Java source files, and the figure shows that file FundamentalExample1.sqlj is open for editing.

The menu bar at the top allows you to access all the functions within JDeveloper. These functions are organized into the following menus: File, Edit, Search, View, Project, Run, Wizards, Tools, Windows, and Help. Some functions can also be accessed using the toolbar, or from the context-sensitive menu obtained by clicking the right mouse button in various areas in the workspace. The Project menu contains the options used to build the executable from the source files. The Run menu contains menu for running and debugging programs.

A toolbar is displayed in the upper-left corner of the IDE and contains buttons that may be used to open and close projects, save files, undo and redo changes, and cut and paste text. The component palette is displayed in the upper-right corner and may be used to add graphical elements to Java applets.

JDeveloper uses a number of panes to display and manipulate programs. The Navigation pane, located in the upper left, displays the files contained in the project. The Structure pane, located below the Navigation pane, displays class names and the names of the methods and variables within each class. The Content pane, located to the right of the Navigation pane, is used to display and edit the contents of files. The Message View pane at the bottom of the screen displays the output from the compiler, and the output from Java programs when they are run.

1.7.2 HelloWorld in JDeveloper

In this section, I show you how to use JDeveloper to compile, run, and debug the HelloWorld.sqlj program. The first thing you do is create a new workspace: go to the File menu and select New Workspace. You should see a blank workspace such as the one shown in Figure 1-4. The new workspace will have the default filename of Untitled1.jws.

Figure 1-4. A new workspace in JDeveloper
figs/sqlj_0104.gif

Next, create a new project by going to the File menu and selecting New Empty Project. Figure 1-5 shows a new project with the default filename MyProject1.jpr.

Figure 1-5. A new empty project
figs/sqlj_0105.gif

Save the new workspace by clicking on Untitled1.jws, selecting the Save As function from the File menu, and saving with the filename MyWorkspace.jws. Then, click on MyProject1.jpr, select the Save As function from the File menu, and save the new project with the filename MyProject.jpr.

Next, create a new SQLJ program: from the File menu, select New. This displays a dialog, shown in Figure 1-6, that allows you to select the type of program to create.

Figure 1-6. The Program Object Type dialog box
figs/sqlj_0106.gif

Click SQLJ File to select it and click OK to continue. The SQLJ Wizard dialog box will be displayed, as shown in Figure 1-7.

Figure 1-7. The SQLJ Wizard dialog box
figs/sqlj_0107.gif

In the SQLJ Wizard dialog, enter "HelloWorld" as the class name and delete the text in the Package field; there's no need to set a package name for this class. Click OK to continue, and a file named HelloWorld.sqlj is then added to your project. Double-click on the HelloWorld.sqlj file in the Navigation pane to open the file in the Content pane. You will see that JDeveloper has created a skeleton of code for the program, as shown in Figure 1-8.

Figure 1-8. The code generated by JDeveloper
figs/sqlj_0108.gif

For the "Hello World" program, you won't be using any of the skeleton code generated by JDeveloper. Instead, cut and paste the code from the HelloWorld.sqlj file shown earlier in this chapter into the code window, making sure to replace all the original code. Your screen should now resemble Figure 1-9.

Figure 1-9. The "Hello World" program in JDeveloper
figs/sqlj_0109.gif

You'll notice that the HelloWorld.sqlj file does not import the same packages as those in the skeleton code. HelloWorld.sqlj imports oracle.sqlj.runtime.Oracle, which includes the Oracle.connect( ) method, and also imports some of the java.sql packages. The skeleton code imports sqlj.runtime.* and sqlj.runtime.ref.*, which support features not used by HelloWorld.sqlj.

Before compiling the HelloWorld.sqlj program, you should save all the files by selecting Save All from the File menu. Next, build the project. From the Project menu, select Make Project "MyProject.jpr". This translates the file HelloWorld.sqlj and compiles the resulting HelloWorld.java file. Once this is complete, run the program by selecting Run "HelloWorld" from the Run menu. JDeveloper runs the program and displays the output from the program in the Message View pane, as shown in Figure 1-10.

Figure 1-10. The Message View pane showing the output from HelloWorld.sqlj
figs/sqlj_0110.gif

1.7.3 Debugging

JDeveloper may be used to debug Java programs. In this section, I'll show you how to set a breakpoint in the HelloWorld.sqlj program and inspect the value of the current_date variable as the program runs. The breakpoint will stop the program right before the SELECT statement is executed. To set the breakpoint, right-click on the following line in the source code:

#sql { SELECT sysdate INTO :current_date FROM dual };

Select Toggle Breakpoint from the resulting context menu. Once the breakpoint is set, the line on which it is set is highlighted and marked with a dot at the start of the line. This is shown in Figure 1-11.

Figure 1-11. A program line on which a breakpoint has been set
figs/sqlj_0111.gif

To begin a debugging session, you run the program in debug mode by selecting Debug "HelloWorld" from the Run menu. Once execution reaches the line containing the breakpoint, control returns to the JDeveloper debugger, as shown in Figure 1-12. Notice the "Source breakpoint" message in the Message View pane at the bottom of the window.

Figure 1-12. The JDeveloper debugger
figs/sqlj_0112.gif

From the debugger, you can step over the current line, step out of the current method, run to the end of the method, or run to the end of the program using the functions in the Run menu. You can also display the values stored in program variables by selecting Inspect from the Run menu. Selecting Inspect causes JDeveloper to display the Inspect dialog box shown in Figure 1-13.

Figure 1-13. The Inspect dialog box
figs/sqlj_0113.gif

In Figure 1-13, current_date has been entered as the symbol to inspect. To display the value stored in current_date, click OK. A window appears containing the value stored in current_date, as shown in Figure 1-14.

Figure 1-14. The current_date value inspected
figs/sqlj_0114.gif

The value stored in current_date is unknown right now because the SELECT statement has not been executed yet. To execute the SELECT statement, select Step Over from the Run menu. This causes the SQLJ debugger to execute the entire SQLJ statement. Then inspect the current_date variable again; this time current_date should contain an actual date, such as the one shown in Figure 1-15.

Figure 1-15. The current_date value with an actual date
figs/sqlj_0115.gif

Select Run from the Run menu to continue the program execution. The date is displayed in the Message View pane, as shown in Figure 1-16.

Figure 1-16. Completed execution of the program
figs/sqlj_0116.gif

JDeveloper is a great tool for creating Java programs, but it is not mandatory for developing SQLJ programs; you can always use the command-line utilities to do the same tasks that JDeveloper does. However, JDeveloper should improve your productivity because it provides a graphical integrated development environment. This section has provided a basic introduction to JDeveloper, and should be enough to get you started if you have access to this tool.

< BACKCONTINUE >

Index terms contained in this section

.jpr file extension
.jws file extension
applets
      Oracle JDeveloper
applications
      Oracle JDeveloper
breakpoint, setting
Content pane, Oracle JDeveloper
debugging programs with JDeveloper
Edit menu, Oracle JDeveloper
EJB (Enterprise JavaBeans)
      JDeveloper and
execution
      HelloWorld.java
File menu, Oracle JDeveloper
Hello World program
      Oracle JDeveloper
Help menu, Oracle JDeveloper
IDE (integrated development environment), JDeveloper
integrated development environment (IDE), JDeveloper
java.sql packages
JavaServer Pages
JDeveloper
      debugging Java programs
      HelloWorld.sqlj
      panes
      projects
      workspace
JSP (JavaServer Pages)
      Oracle JDeveloper
menu bar, Oracle JDeveloper
Message View pane, Oracle JDeveloper 2nd
Navigation pane, Oracle JDeveloper
Oracle Java Stored Procedures
      Oracle JDeveloper
Oracle JDeveloper
panes, Oracle JDeveloper
Project menu, Oracle JDeveloper
projects, JDeveloper
Run menu, Oracle JDeveloper
Search menu, Oracle JDeveloper
SELECT statement
servlets
      Oracle JDeveloper
SQLJ Wizard dialog box
sqlj.runtime.*
sqlj.runtime.ref.*
sqlj_project.jpr
sqlj_workspace.jws
Structure pane, Oracle JDeveloper
Tools menu, Oracle JDeveloper
View menu, Oracle JDeveloper
Windows menu, Oracle JDeveloper
Wizards menu, Oracle JDeveloper
workspace, JDeveloper
      .jws file extension
      creating



Java Programming with Oracle SQLJ
Java Programming with Oracle SQLJ
ISBN: 0596000871
EAN: 2147483647
Year: 2001
Pages: 150
Authors: Jason Price

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net