facebook

Connecting to a Database

Connecting to a database using the Database Explorer is a two step process. First, configure the Database Explorer driver for your database, and then open a database connection. Driver configuration is a one-time configuration task for each database you want to use. In this tutorial, you will learn to:

  • Configure a JDBC database driver
  • Create a database profile and connection

This feature is available in MyEclipse.

1. Configure the Database Connection

This tutorial uses an Oracle database as an example. The process of creating a connection is similar for all other JDBC drivers. To learn about JDBC visit the Sun website.

  1. Select Window>Perspective>Open Perspective>Database Explorer This menu option was updated in MyEclipse 2017. For prior versions, click here. . The first time you open the perspective, the Database Browser view shown on the left contains only the preconfigured MyEclipse Derby driver.

    dbworkbench
    Database Explorer perspective tools

    You need to create a new driver for each separate connection to a database.

  2. Click on the DB Browser view, and select New.


    Adding a new driver
  3. Select Oracle (Thin driver) from the Driver Template drop-down.
  4. Type oracle in the Driver name field.
  5. Modify the template URL provided to the correct connection string. In this example, the local Oracle server is jdbc:oracle:thin:@localhost:1521:dbtest.
  6. Fill out the User name and Password fields with appropriate values for your server. If you do not want to save your password, there is no need to fill in the Password field.


    Database driver details
  7. Click the Add JARs button.
  8. Browse to location of the JDBC driver JAR file or classes folder, select it, and click Open.


    Selecting Oracle JDBC driver JAR file

    Note: In this case, the Oracle JDBC connector was found as part of the oracle installation files.

  9. Inspect the value of the Driver Class Name. The ojdbc6.jar file contains two possible driver classes that can be selected from the Driver classname drop-down.
  10. Select oracle.jdbc.driver.OracleDriver from the Driver classname drop-down, and click Finish.

FieldRequiredDescription
Driver nameYesA descriptive name that will appear Database Browser view.
URLYesThe database connection string. Each database has its own URL structure, e.g. jdbc:oracle:thin://
User NameNoThe login name when creating a connection to the database.
PasswordNoThe password when creating a connection to the database.
Driver JARsYesUser managed JARs in this list are added to the Driver Manager’s classpath. If the database driver is not available on the the Java Classpath (see above) it should be added here.
Driver Class NameYesThe fully qualified Java classname of the JDBC driver class. This class must be accessible on the combined classpath locations of the Java Classpath + Driver JARs lists.
Save PasswordNoSelecting this option instructs the Database Explorer to store the password locally. If this option is selected, you will not be prompted for your password when you attempt to connect.
Open on Eclipse StartupNoSelecting this option will instruct the Database Explorer to automatically create this connection during the Eclipse startup process.


The new driver appears the DB Browser view.


DB Browser view with the Oracle driver

2. Open the Database Connection

Open a connection when MyEclipse is started or after any event that results in the database connection being dropped, such as a database server restart.

  1. Right click the driver, and select Open connection.


    Opening a database connection

    If the connection profile is configured with the Save Password option disabled, then the Open Database Connection wizard opens.


    Entering the user name and password
  2. Enter the password.
  3. Select the AutoCommit checkbox if you need changes to the database to be committed immediately. You can set the default auto-commit setting in the MyEclipse Database Explorer preferences.
  4. Click OK to initiate the database connection process. A new database connection opens and is displayed in the DB Browser.


    New database connection in DB Explorer
Note: Connections remain open if you close the Database Browser view or switch to a different perspective.