Configuring Database Access in Eclipse 3.0 with SQLExplorer
Pages: 1, 2
Support for Other Databases
The example JDBC connection is configured with the MySQL database. A JDBC connection may be configured with another database by selecting the driver node for the database in the Drivers tab. By specifying the driver class and connection URL for the selected database, a JDBC connection gets configured with the database. The driver class, the connection URL, and the driver .jar file for some of the other databases are listed below:
- DB2
- Driver Class:
COM.ibm.db2.jdbc.app.DB2Driver - Connection URL:
jdbc:db2:<database> - Driver .jar/.zip:
db2java.zip
- Driver Class:
- Sybase
- Driver Class:
com.sybase.jdbc2.jdbc.SybDriver - Connection URL:
jdbc:sybase:Tds:<host>:<port>/<database> - Driver .jar/.zip:
jconn2.jar
- Driver Class:
- Oracle
- Driver Class:
oracle.jdbc.driver.OracleDriver - Connection URL:
jdbc:oracle:thin:@ <host>:<port>:<sid> - Driver .jar/.zip:
classes12.zip
- Driver Class:
- SQLServer
- Driver Class:
com.microsoft.jdbc.sqlserver.SQLServerDriver - Connection URL:
jdbc:microsoft:sqlserver://localhost:1433 - Driver .jar/.zip:
mssqlserver.jar,msbase.jar,msutil.jar
- Driver Class:
- PostgreSQL
- Driver Class:
org.postgresql.Driver - Connection URL:
jdbc:postgresql://<server>:<port>/<database> - Driver .jar/.zip:
postgresql.jar
- Driver Class:
In the above list, <database> is the database
instance, <port> is the database port,
<sid> is the database SID, and
<server> is the database server.
Accessing Database Data
We configured the Eclipse IDE with the SQLExplorer plugin in the
previous section. Next, we shall retrieve and modify the data from
the example table Catalog. If a database is accessed
from a command-line SQL client, table data is retrieved with the
following (all on one line):
SQL>SELECT catalogId, journal, publisher, date,
title, author from Catalog;
This displays the data as a text table. With the GUI SQL client
SQLExplorer, the data is displayed as a structured table.
SQLExplorer also generates the SQL scripts to create a table and
select from it. If a table structure is displayed in a command-line
client with the DESC command, only the column name,
column type, column size, and "not null" values get displayed. With
SQLExplorer, the indexes, primary key, and foreign key values are also displayed.
Select the Database Structure View tab in the
SQLExplorer perspective in Eclipse. To display the structure of the
Catalog table, select the
Database>test>TABLE>Catalog node in the
Database Structure View. Figure 13 shows the Catalog table
structure.

Figure 13. Database Structure View
The Columns tab displays the columns listed in the Table below:
| Header | Description |
| Column Name | The column name in the table. |
| Data Type | The data type for the column. |
| Size | The column size. |
| Decimal Digits | The decimal digits in the column data. |
| Default Value | The default value of the able column. |
| Accept Null Value | Specifies if the column takes null values. |
| Comments | Comments on the table column. |
To display the data in the table selected in the
TABLE node, select the Preview tab.
Figure 14 shows the table data for the Catalog table. Additional
information about a table is displayed with the
Indexes, Primary Key, Foreign
Key, and Row Count tabs.

Figure 14. Listing the table data
To create a SQL script to create the table, right-click on the table node and select Create Table Script, as shown in Figure 15.

Figure 15. Creating table script
This creates the SQL script to create the selected table and
displays it in the SQL Editor of the SQLExplorer
perspective, which is shown in Figure 16.

Figure 16. Table script
The data displayed in the Preview tab of the Database Structure View is retrieved with the default Select query, which includes all of the columns in the table. To display the default Select query, right-click on the table node and select "Generate Select in Sql Editor," as shown in Figure 17.

Figure 17. Generating the default select query
The default query to retrieve data from the catalog table gets
displayed in the SQL Editor, as Figure 18 illustrates. Note that
the SELECT queries displayed in the SQL Editor do not
have a semicolon (;) at the end of the SQL
statement.

Figure 18. Select query
The query may be customized to display only some of the columns
in the table. For example, modify the Select query to display all of
the columns except the CatalogId column. To run the
SQL script, select the Execute SQL button. The data
from the modified select query gets displayed in the SQL
Results frame, as shown in Figure 19.

Figure 19. Selecting table data with custom SELECT
query
Next, the catalog table shall be updated with an SQL script in the SQL Editor. For example, modify the title from "Five Favorite Features from 5.0" to "New Features in JDK 5.0." The SQL script to update the catalog table is run in the SQL Editor as shown in Figure 20.

Figure 20. Update SQL script
The table data gets updated. Run the default select query on the modified table to display the modified data in the SQL Results frame. Figure 21 shows the modified catalog table data.

Figure 21. Modified table data
Next, delete a row from the table with a DELETE SQL
statement in the SQL Editor, as shown in Figure 22. The table row
with CatalogId='3' gets deleted from the table.

Figure 22. DELETE SQL Script
Run the default select query to display the modified table data. The SQL Results frame table does not include the deleted row, as shown in Figure 23.

Figure 23. Table data with row deleted
By configuring the SQLExplorer plugin in Eclipse, the IDE acquires the advantages of a GUI SQL client over a command-line client.
Conclusion
For the example database table, a JDBC connection was established with the MySQL database. The SQL Explorer may also be used to configure a connection with other databases, which include DB2, Sybase, Oracle, HSQLDB, SQL Server, and PostgreSQL.
Resources
Deepak Vohra is a NuBean consultant and a web developer.
|
Related Reading Eclipse Cookbook |
Return to ONJava.com.
-
Change the driver
2008-08-07 08:57:39 Ameercim [View]
-
installation on MacOS X
2005-10-12 16:52:21 monica1 [View]
-
installation on MacOS X
2005-10-12 17:02:09 Deepak Vohra | [View]
-
installation on MacOS X
2005-10-12 17:21:57 monica1 [View]
-
installation on MacOS X
2005-10-12 17:42:31 Deepak Vohra | [View]
-
installation on MacOS X
2005-10-12 17:51:59 monica1 [View]
-
installation on MacOS X
2005-10-13 08:31:12 Deepak Vohra | [View]
-
installation on MacOS X
2005-10-13 13:01:31 monica1 [View]
-
Problems
2005-09-28 06:19:29 aguevara [View]
-
Problems
2005-09-28 10:09:14 Deepak Vohra | [View]
-
Problems
2005-11-30 14:48:57 step1up [View]
-
MySQL-JDBC with Eclipse -Problem solved
2007-09-09 23:05:27 sugam.sharma [View]
-
Problems
2005-12-08 10:26:06 subguys [View]
-
Problems
2005-12-01 09:01:54 Deepak Vohra | [View]
-
Problems
2005-11-30 16:42:21 Deepak Vohra | [View]
-
Problems
2006-05-04 12:15:17 RajeshRangachari [View]
-
Problems
2006-05-04 14:34:01 Deepak Vohra | [View]
-
Use Free TOAD
2005-06-01 18:21:47 j2eecop [View]
-
Use Free TOAD
2005-07-09 16:39:06 Oyku [View]
-
Use Free TOAD
2005-06-05 03:09:12 lenkite [View]
-
Use Free TOAD
2005-11-01 09:12:12 mrmeow1 [View]
-
Use Free TOAD
2005-06-09 10:29:36 Deepak Vohra | [View]
-
Use Free TOAD
2006-09-19 18:50:34 TOracle [View]
-
Use Free TOAD
2005-06-02 07:45:09 Deepak Vohra | [View]
