|
|||||||||||||||||||||||||||
Outline |
|||||||||||||||||||||||||||
1. PrefaceThis document was written using Sun JDK 1.4.2, Eclipse 3.2, MyEclipse 5.0 and Oracle 9.2.x. All screenshots are based upon the default user interface settings for Eclipse, MyEclipse Enterprise Workbench, and Windows XP. If you experience difficulty with the instruction of this document, please see the User Feedback section for how to provide feedback to the MyEclipse documentation team. |
|||||||||||||||||||||||||||
2. RequirementsBelow is a list of requirements for this Tutorial:
|
|||||||||||||||||||||||||||
3. IntroductionDevelopment of Java enterprise applications typically involves working with relational databases. To support this dimension of development, MyEclipse Enterprise Workbench provides the Database Explorer, a suite of database application development tools. The Database Explorer (DE) consists of the following features:
This Tutorial will demonstrate how to perform the following Database Explorer tasks:
|
|||||||||||||||||||||||||||
4. Creating a Database ConnectionThis section demonstrates the process for configuring and connecting the Database Explorer to a Oracle database server. The process is similar for all other JDBC drivers. To learn about JDBC visit this link . Connecting the Database Explorer to a database is a 2 step process:
Step 1 is a one-time configuration task for each database that you wish to use. Step 2 must be performed when MyEclipse is started or after any other event that results in the database connection being dropped, such as a database server restart. |
|||||||||||||||||||||||||||
4.1 Creating a Database DriverThe first task is to configure the Database Explorer JDBC driver for your database. Drivers and their resulting connections are managed in the Database Browser. To access the Database Browser, open the Database Explorer Perspective. Select Window > Open Perspective > Other > MyEclipse Database Explorer followed by OK (see Figure 2).
Figure 3 shows the Database Explorer perspective with some of the
main database tools highlighted. The first time you open the
perspective the Database Browser view shown on the left will only
contain the preconfigured MyEclipse Derby driver. Versions of
MyEclipse prior to 5.5 will probably see an empty view.
You will need to create a new driver for each separate connection to a database. Create a new driver using these steps.
Note: Prior to starting this example the Oracle JDBC connector was downloaded to a local directory.
Inspect the value of the
Driver Class Name. The
ojdbc14.jar file contains 2
possible driver classes which may be selected from the Driver
Class Name drop-down list.
Table 2. New Connection Profile wizard field definitions
The new driver will now show in the DB Browser view.
|
|||||||||||||||||||||||||||
4.2 Opening a Database Connection
If the connection profile is configured without the Save password option then the Open Database Connection Wizard will appear (see Figure 9).
At this point a new database connection will be opened and displayed in the Database Browser.
Note: Connections will not be closed if you close the Database Browser view or switch to a different perspective. |
|||||||||||||||||||||||||||
5. Working with DatabasesThis section will introduce you to the Database Explorer tools that enable database browsing and SQL development. These tools include:
|
|||||||||||||||||||||||||||
5.1
Browsing a Database
|
|||||||||||||||||||||||||||
5.2
SQL Editing and Snippet Execution
|
|
Special Notice regarding SQL code completion The SQL code completion features requires the metadata of an editor's associated database be preloaded. By default, SQL code completion is disabled to avoid severe performance problems that may result from reading the metadata of very large database or retrieving this information over very low bandwidth database connections.
To optimize metadata retrieval consider using a
schema filter. Select this
link to learn more.
|
Figure 16a. Standard SQL syntax code assistance
Figure 16b. Code assist for schema names
Figure 16c. Code assist for table names
Figure 16d. Completed SQL statement
![]()
Figure 17. Activating Database Browser synchronization for the DEPT table in the SCOTT schema
icon or
Ctrl + F9.
The
action will execute the selected snippet. In the case no statements are selected, as in this example, the entire SQL Editor text will be executed. The query results are presented in the SQL Results view as shown in Figure 22.
![]()
Figure 18. Results from query execution
MyEclipse provides a number of wizards and actions making it easy to create and delete Tables, Relationships and Indices.
Figure 19. Invoking the New
Table Wizard
Figure 20. New Table Wizard
- Table Info
Figure 21. New Table Wizard
- Columns
Figure 22. New Column Wizard
- Primary Key
Figure 23. New Column Wizard
Figure 24. New Table Wizard
Figure 25. New Table Created
Figure 26. Invoking the New
Foreign Key Wizard
Figure 27. New Foreign Key
Wizard
Figure 28. New Foreign Key
Wizard Completed
Figure 29. New Foreign Key
in the Table/Object Info view
Figure 30. Invoking the New
Index Wizard
Figure 31. New Index Wizard
Figure 32. New Index Wizard
Completed
Figure 33. New Index in the
Table/Object Info view
Figure 34. Dropping an Index
Figure 35. Dropping a Foreign
Key
The Database Explorer provides an Edit table view which can be used to edit records already present in your database. To use this feature, begin by opening the view.
![]()
Figure 37. Launching Table Data Editor on echo_message table
In the example below we are editing the SAL column value in row 1.
![]()
Figure 38. Table Data Editor
The Database Explorer provides two SQL generation utilities, a
table creation script generator and an example SQL query
generator.
To generate a Data Definition Language (DDL) script for an existing table do the following:
![]()
Figure 39. Activating "Create Table Script" featureThis feature will generate a DDL script for recreating the selected table and display it in a new SQL Editor (see Figure 40)
![]()
Figure 40. Newly created Table Script DDL
To generate an example SELECT statement for a table do the following:
![]()
Figure 41. Generate SQL Select statement from tableThis feature will generate a SELECT * statement and display it in a new SQL Editor (see Figure 42)
![]()
Figure 42. New created SELECT statement in SQL Editor
This section provides a brief description of the features for viewing database and table detail.
The SQL History view presents a list of all recent SQL statements executed on the database connection selected in the Database Browser. This view provides useful menu actions such as reopening the SQL statement in a new editor as shown in Figure 43.
Figure 43. SQL History List
The Database Connection Information view presents detailed information about the database connection selected in the Database Browser. As you select different database connections the information is updated accordingly.
Figure 44. Database Connection
Information
The Table Information view presents detailed metadata information for the selected database table in the Database Browser (see Figure 45) . The metadata information is presented in read-only mode.
Figure 45. Table
Information view
There are advanced features, such as performance optimizations, that Database Explorer users who work with large databases should know about. In this section we introduce schema filtering to enable users to determine how much metadata to fetch when a database connection is opened.
When opening a database connection in the Database Browser, the default behavior is to fetch information about each database schema. The Database Explorer allows you to optionally filter the schemas managed by a database connection. The primary reasons for applying a schema filter are optimization related, such as:
Schema filters are created as part of a connection profile's definition and are therefore managed using the Connection Profile Wizard.
To create a schema filter do the following:
Note: The Add action will attempt to connect to the database and retrieve a list of all schemas.
![]()
Figure 46. Schema Details page of the Connection Profile Wizard
Figure 48 shows that the"Selected schema list" has been updated with the newly selected schemas.
Figure 49 depicts a database connection for the MySQL Test database with filter enabled.
![]()
Figure 49. Database connection with specified schemas
The default command separator is the semicolon
(;). This implies that all SQL commands and
queries will be terminated by the
; character.
However, in more complex scripts, the
; is often used as an internal separator while
other strings are used as the command separator. Such scripts
will not execuite correctly when the semicolon is the command
separator.
You can change the command separator by using the SQL Editor's
Command Separator combo to select from an
existing set of separators or you may type in your own.
![]()
Figure 50. An example of an SQL Server script where the ; is used as an internal separator and "go" as the command separator.
This concludes your tutorial into using the MyEclipse Database Explorer features. Additional Tutorial documents are available that introduce working with Hibernate along with the Database Explorer, as well as working Web Projects, editing HTML, application server configuration, and enterprise application projectst. For more information visit the MyEclipse Tutorial library.
If you have comments or suggestions regarding
this document please submit them to the
MyEclipse
Documentation Forum.