Creating a MySQL data source using WebSphere Application Server

DATABASE CONNECTIVITY

Recently, Senior Technical Editor Dan Velasco wrote an article on how to connect to the popular open source database MySQL from WebSphere Studio Application Developer (see http://www.webspherepower.com/issues/issue200310/00001111001.html ). Once you've created your application using MySQL, though, you'll want to deploy it to an application server, presumably WebSphere Application Server. To use MySQL on the application server, you will need to create a JDBC (Java Data Base Connectivity) data source if you want to take advantage of the connection pooling capabilities inherent in the WebSphere platform.

Creating a JDBC MySQL data source involves three independent steps, all accomplished with the WebSphere Application Server's Administrative Console facility. In order, these three steps are:

  • Create a MySQL JDBC provider.
  • Create the basic MySQL data source configuration.
  • Add six custom properties to the MySQL data source configuration.

We'll walk through each of these steps, one step at a time.

Open the WebSphere Application Server Administrative Console
JDBC data sources are created in the WebSphere Application Server using the built-in Administrative Console, a Struts 1.0 application that comes bundled with the product. To activate the Administrative Console, open a Web browser and enter the following URL:

https ://<; server-name>: 9043/admin

Figure A illustrates the screen that will come up if all is working correctly with your application server and the Administrative Console has been enabled.

FIGURE A
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Log into your Administrative Console. Roll over picture for a larger image.

If you have security turned on for the Administrative Console, the screen will also contain a password field and you will have to enter a valid user name and password to authenticate to the server. If you do not have security turned on, you can enter any username that you wish. Once you authenticate to the server, you will see the home page of the Administrative Console, depicted in Figure B.

FIGURE B
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Welcome home. Roll over picture for a larger image.

Create the JDBC provider
The first step in creating the Data Source is to create the MySQL JDBC provider. Open up the Resources menu by clicking on the little plus sign (+) in front of the word Resources and then click on JDBC Providers. This should bring you to the screen found in Figure C.

Creating a MySQL data source using WebSphere Application Server (continued)

FIGURE C
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Click New to create a providers. Roll over picture for a larger image.

Click on the New button, which should bring you to the JDBC Provider Configuration entry screen, shown in Figure D.

FIGURE D
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Configure your new provider. Roll over picture for a larger image.

Enter the JDBC Provider configuration parameters using the following information:

  • Name: MySQL
  • Description: MySQL JDBC 2.0-compliant Provider configuration
  • Classpath: $ (User-defined_JDBC_DRIVER_PATH) / mysql-connector-java-3.0.9-stable-bin.jar (or the appropriate name for the version of MySQL Connector / J that you are using)
  • Native Library Path: <leave blank>
  • Implementation Classname: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource

When you have finished entering the data, click on OK. If there are no data entry errors, this should take you back to the list of JDBC Providers, where you should now see your new MySQL JDBC Provider displayed as shown in Figure E.

FIGURE E
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

You're now the proud owner of a new provider. Roll over picture for a larger image.

You should also see a message at the top of the screen informing you that changes have been made and indicating that you should save these changes to the Master Configuration. While you can take that step at this point, we will be making further changes and you might as well wait until everything has been completed and then save everything at once.

"The secret trick to making this work is the Datasource Helper Classname"

Create the base JDBC data source entry
Click on the name of your new MySQL JDBC Provider entry to return to the JDBC Provider Configuration screen. Scroll to the bottom of the screen and click on the Data Sources link in the Additional Properties section, as shown in Figure F.

FIGURE F
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Scroll down for the Additional Properties section. Roll over picture for a larger image.

This should take you to the empty Data Sources list shown Figure G, where you need to click on the New button.

FIGURE G
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Click new to create a new data source. Roll over picture for a larger image.

This will bring you to the Data Source Configuration screen, shown in Figure H.

FIGURE H
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Enter the Data Source configuration parameters. Roll over picture for a larger image.

Enter the Data Source configuration parameters using the following information:

  • Name: <data source name>
  • JNDI (Java Naming and Directory Interface) Name: jdbc / <data source name>
  • Description: <data source description>
  • Statement Cache Size: 10 (the default)
  • Category: <leave blank>
  • Datasource Helper Classname: com.ibm.websphere.rsadapter.ConnectJDBCDataStoreHelper
  • Component-managed Authentication Alias: <leave blank>
  • Container-managed Authentication Alias: <leave blank>

The secret (and not very well publicized) trick to making this work is the Datasource Helper Classname. Without the proper datasource helper, you will run into all kinds of interesting challenges trying to get this to work.

When you have finished entering the data, click on OK. If there are no data entry errors, this should take you back to the list of JDBC data sources, where you should now see your new MySQL JDBC data source displayed, shown in Figure I .

Creating a MySQL data source using WebSphere Application Server (continued)

FIGURE I
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Here's your new data source. Roll over picture for a larger image.

Add MySQL-specific custom properties to your data source entry
Click on the name of your new MySQL JDBC data source entry to return to the JDBC data source configuration screen. Scroll to the bottom of the screen as shown in Figure J and click on the Custom Properties link in the Additional Properties section.

FIGURE J
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Get ready to configure some custom properties. Roll over picture for a larger image.

This should take you to the empty Custom Properties list, shown in Figure K, where you can begin entering the six custom properties necessary to complete your MySQL Data Source entry.

FIGURE K
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Now you can configure some hidden, but very important options. Roll over picture for a larger image.

The six custom properties, which are another difficult to locate tidbit of critical information, and their respective values are:

Name Type Value
databaseName java.lang.String <database-name>? autoReconnect = true
factory java.lang.String com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory
password java.lang.String <password>
port java.lang.String 3306 (or your MySQL port, if you have changed it)
serverName java.lang.String <server=name>
user java.lang.String <user-name>

Custom properties are entered one property at a time using the Custom Property Configuration screen. To enter your first property, click on the New button above the empty property list, which should take you to the Custom Property Configuration screen illustrated in Figure L.

FIGURE L
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Enter the property name, Java type, and property value, then click OK Roll over picture for a larger image.

Enter the property name, Java type, and property value, then click OK. Repeat this process for all six of the properties listed above.

When you have completed entering all of the custom properties, the last step is to save all of the changes that you have made to the master configuration. After successfully entering the data for the last custom property, you should still be on the list of custom properties for your new data source, as shown in Figure M.

FIGURE M
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Here you can see all your custom properties Roll over picture for a larger image.

At the top of the screen, you should still see the message about saving your changes to Master Configuration. Clicking on the word Save in that message will take you to the Save to the Master Configuration screen shown in Figure N.

FIGURE N
Creating a MySQL data source using WebSphere Application Server
Creating a MySQL data source using WebSphere Application Server

Don't forget to save your configuration. Roll over picture for a larger image.

Click on the Save button to save your newly completed MySQL JDBC data source configuration and you are ready to start using your new data source.

Wrap-up
By following these three simple steps, you can create your first MySQL JDBC data source. If you need additional MySQL data sources in the same server instance, creating the rest is even easier. Step one, creating the MySQL JDBC Provider only has to be done once per server; additional data sources can be added using the same provider by just completing steps two and three. Just make sure that your. jar file for the MySQL JDBC driver is accessible to the server and your new data source should be ready to go .

分类:Java 时间:2010-03-29 人气:360
分享到:
blog comments powered by Disqus

相关文章

  • Hunan ADC platform interface data transmission program 2011-05-28

    The program mainly to explain that the interface is sending data to the ADC platform, which interface is receiving data from the ADC platform. Hunan ADC platform interface data transmission program http://www.ossez.com/forum.php?mod=viewthread&tid=10

  • MySQL Cluster Introduction and Configuration Detailed 2010-12-01

    1. To understand whether you should use MySQL Cluster. Nodes to reduce pressure on data centers and large amounts of data processing, using the MySQL distribution, one or more of the application corresponds to a MySQL database. Several MySQL database

  • ubuntu nginx + mysql + php5-fpm + wordpress detailed configuration 2010-05-01

    Original link: http://www.netroby.com/article-1367.html The article wrote it myself, only in their own independent javaeye blog and blog. Welcome reproduced, thank acknowledgment. ubuntu 8.04 LTS 64-bit systems nginx + mysql + php5-fpm + wordpress de

  • Using WebSphere Studio Application Developer 5.0 to create and test message-driven Bean 2010-08-25

    From: http://www.ibm.com/developerworks/cn/websphere/techjournal/0211_barcia/barcia.html WebSphere Studio Application Developer 5.0 supports message-driven bean (message-driven bean, MDB). With MDB, EJB container can asynchronously receive messages?

  • MySQL + php + Apache environment configuration (change) 2010-09-20

    php configuration of the environment, for the novice, it is definitely an annoying thing. Always encounter this problem, and take many detours. So today specifically wrote this profile document, believed by following these steps you will be successfu

  • Mysql windows free installation configuration 2010-08-29

    1 Download MySQL Extract MySQL (X: \ Program Files \ MySQL \) MySQL installation directory 2 new my.ini In X: \ Program Files \ MySQL \ my.ini file under the build, says my.ini [Mysqld] # Set the mysql installation directory basedir = X: \ \ Program

  • Mysql installation under Linux configuration 2010-11-09

    1 the MySQL installation files for Linux Installing MySQL for Linux requires the following two files: MySQL-server-5.1.7-0.i386.rpm Download address: http://dev.mysql.com/downloads/mysql/5.1.html, open this page, scroll down page to find the "Linux x

  • Mysql individual. Two-way replication configuration 2011-02-23

    2 ways, you can modify the configuration file or by MySqlAdministrator my.ini configuration management tools, MySqlAdministrator tool to configure the final product is my.ini file, and now as an example to MySqlAdministrator There are two machines A:

  • Enable the MySQL slow query log configuration view 2011-10-07

    MySQL slow query logging system for tracking PHP + MySQL MySQL under useful load tuning issues, such as installing a lot of Discuz! Plug-in user, this can probably troubleshoot a problem that the plugin code. In fact, enable the MySQL slow query log

  • Ubuntu under jdk, mysql, tomcat installation and configuration 2010-11-14

    A, jdk installation 1. Download and install sun jdk First, http://java.sun.com download jdk-6u20-linux-i586.bin 2. To authorize the downloaded file and move to the specified folder Code: $ Sudo chmod u + x jdk-6u20-linux-i586.bin 3. Executable file t

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 1.154 (s). 12 q(s)