Connecting to a Database in MyEclipse

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

Duration Time: 15 Minutes

Start Tutorial Now

Don't have MyEclipse? Download Now

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>Open Perspective>MyEclipse Database Explorer. The first time you open the perspective, the Database Browser view shown on the left contains only the preconfigured MyEclipse Derby driver. 

    Database Explorer perspective toolsYou 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 fileNote: 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.

    Field

    Required

    Description

    Driver name

    Yes

    A descriptive name that will appear Database Browser view.

    URL

    Yes

    The database connection string. Each database has its own URL structure, e.g. jdbc:oracle:thin://

    User Name

    No

    The login name when creating a connection to the database.

    Password

    No

    The password when creating a connection to the database.

    Driver JARs

    Yes

    User 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 Name

    Yes

    The 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 Password

    No

    Selecting 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 Startup

    No

    Selecting 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 connectionIf 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.