Creating a MySQL data source using WebSphere Application Server

sponsored links
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 .
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Creating a MySQL data source using WebSphere Application Server

  • jdbc even ORACLE, SQLServer2000, mysql ways

    According to other people say can make a ride to one of the clear step by step, not as easy to write your own ideas! 1. Even the oracle The direct use of the oracle are provided give a jar package jdbc: oracle alone is installed, and 10g of oracle on ...

  • hibernate brief introduction

    1: hibernate, what are? 1: hibernate is a JDBC package is responsible for object persistence, in the middle layer, in the application and database has played a role as a bridge between a mapping tool. Second: Why is the use of hibernate? 1: the use of hib

  • Properties with 6 supplementary hibernate.cfg.xml configuration

    In some special circumstances, we may be saved in the database connection information config.properties document, for example, make a install.jsp to modify config.properties documents, implementation of online information on the database configuration. At

  • JPA data source data source to configure Tomcat conversion essay questions

    To the JPA in the use of the development process, sometimes used in the data source conversion problem, The following methods are only my personal experience of a situation and its solutions, if different, please everyone posted for your reference encount

  • jsf + EJB development examples

    I wrote it myself a simple example of jsf1.2 + EJB3.0, mainly just for study JSF are brothers, for example, is very simple, one would look. Examples of content that is for a staff increase, deleted, changed, for example, includes two projects, one is ...

  • JAVA EE JSP_JNDI

    dsfdsa http://lindows.javaeye.com/admin/blogs/213348 Tomcat 6 with the connection pool data source configuration http://www.blogjava.net/ec2008/archive/2008/07/19/216063.html project: test Driver path: D: \ workspace \ test \ WebRoot \ WEB-INF \ lib ...

  • The EJB3 Persistence

    EJB3 persistence with Hibernate is very similar to the mechanism: Environment: Server: JBOSS5.0 Database: MySQL5.0 1. Set up a data source First of all, in jboss-5.0.0.GA \ server \ default \ deploy, the establishment of a database used to connect the dat

  • can not be represented as java.sql.Timestamp

    Development of procedures for the use of hibernate when, some time there is no need to fill in the fields, but after the hibernate query time reported "Java.sql.SQLException: Value'0000-00-00 'can not be represented as java.sql.Timestamp ...

blog comments powered by Disqus
Recent
Recent Entries
Tag Cloud
Random Entries