Referencing MySQL databases

The last step is to configure the data sources that the application is going to use at WebLogic, and create links to these databases at Eclipse. This kind of connection is a data source (DS) inside WebLogic Server.

Tip

In earlier versions of WebLogic Server, you were supposed to configure both a connection pool and a data source. Now, both concepts are contained within a data source, which is a logical move—sharing a pool of connections but not the link to it (the data source) may lead to problems, since no application could predict if others were using the underlying pool, and worst yet, how.

Creating WebLogic data sources

As we just finished enabling the domain at Eclipse, we can start the server from there:

  1. In the Servers tab, right-click on the domain name and then Start from the context menu, or if you prefer to start it manually, OEPE will synchronize to show that the server is up and running.
  2. The focus will switch to the Console tab. After 15 to 30 seconds, a message stating that the server is running is going to show up (<BEA-000360><The server started in RUNNING mode.>) and the focus will get back to the Servers tab.
  3. Right-click again on the server name, select Go To, and then Admin Console to open a browser window pointing to the administration console.

    Note

    The default address of the administration console is http://localhost:7001/console.

  4. Enter your administrator's credentials (the username and password you set when creating the domain) and click on Login. The initial page shows you a list of basically every resource you can configure. Find the link Data Sources inside the Services group and click on it.
  5. On the new page, click on New, then click on Generic Data Source and then on Next.
  6. Fill the fields as follows and click on Next:
    • Name: Store DS
    • JNDI Name: jdbc/tickets/store
    • Database Type: MySQL
  7. Leave the default value for the driver, MySQL's Driver (Type 4) Versions: using com.mysql.jdbc.Driver, and click on Next.

    Tip

    Oracle WebLogic Server already comes with a MySQL driver, so we don't need any additional downloads in order to create a Data Source that points to this database engine.

  8. Select the Logging Last Resource option and go to the next page.

    Note

    As we're using a driver that doesn't support global (distributed) transactions—transactions that coordinate several resources as a single unit—we will emulate its behavior by enabling the Emulate Two-Phase Commit option.

    The Logging Last Resource option is an alternative to this emulation that brings performance and reliability improvements. For detailed advantages and considerations about it, check the Web resources section at the end of the chapter.

  9. Enter the following values and click on Next:
    • Database Name: store_db
    • Host Name: localhost
    • Port: 3306 (this is the default value)
    • Database User Name: store_user
    • Password and Confirmation: store
  10. There's no need to change any values here. Click on the Test Configuration button at the top of the page and a message Connection test succeeded must show up right above the test button. Click on Next.

    Note

    If the test returned an error, you must check the message and figure out what went wrong—an invalid credential, MySQL server is down or a typo are the most likely causes.

  11. Finally, select the server on which the resource is to be made available—AdminServer is the only one on our domain—and click on Finish to commit the changes.
  12. Now, create another data source following the same steps, but changing these fields:
    • Name: Theater DS
    • JNDI Name: jdbc/tickets/theater
    • Database Name: theater_db
    • Database User Name: theater_user
    • Password and Confirmation: theater

You must have a list of data sources like the following one by now:

Creating WebLogic data sources

Adding database connections to Eclipse

Now we're going to inform Eclipse/OEPE about the databases, so we can use its wizards later. Go back to Eclipse and execute the following steps:

  1. Find or open the Data Source Explorer view (In the menu, navigate to Window | Show View | Other | Data Source Explorer).
  2. Right-click on Database Connections and select New... in the context menu.
  3. Select MySQL, type MySQL – Store as Name then click on Next.
  4. Click on the New Driver Definition button beside the Drivers dropdown.
  5. Select MySQL JDBC Driver version "5.1" and go to the Jar List tab.
  6. Select the entry mysql-connector-java-5.1.0-bin.jar and click on Remove JAR/Zip, then click on Add JAR/Zip.
  7. On the pop-up window, navigate to $MW_HOME and continue to the subdirectory ./oracle_common/modules/mysql-connector-java-commercial-5.1.22/.
  8. Select the file mysql-connector-java-commercial-5.1.22-bin.jar and click on OK.
  9. The New Connection Profile window is going to pop up, change the following fields:
    • Database: store_db
    • URL: jdbc:mysql://localhost:3306/store_db
    • User name: store_user
    • Password: store
    • Check Save password
    Adding database connections to Eclipse
  10. Click on Test Connection, and you should see a Ping succeeded! message.

    Note

    If this is not the case, go back, check if you entered the correct values and run the test again. You may need to start up the MySQL Server.

  11. Click on Finish.

Now we need to execute the same steps mentioned earlier, but this time pointing to the Theater database. Here are the fields you need to change:

  • Connection name: MySQL – Theater
  • Database: theater_db
  • URL: jdbc:mysql://localhost:3306/theater_db
  • User name: theater_user
  • Password: theater

The last step is to create and configure an OpenLDAP server, which will be accessed by WebLogic's instance when we discuss security features.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.249.210