This post originated from an RSS feed registered with Java Buzz
by Marc Logemann.
Original Post: DB2 DataSources and Tomcat5
Feed Title: Marc's Java Blog
Feed URL: http://www.logemann.org/day/index_java.xml
Feed Description: Java related topics for all major areas. So you will see J2ME, J2SE and J2EE issues here.
Setting up DataSources with Tomcat is not too hard, but doing it without using the default org.apache.naming.factory.DbcpDataSourceFactory or org.apache.commons.dbcp.BasicDataSourceFactory (where is the difference by the way?) needs some kind of research.
Because my target database is a DB2 which runs on Windows at the moment and will reside on an IBM iSeries during production, there are some options. For development i am using the db2 on windows, so i searched what IBM offers with their universal driver for db2 (db2jcc.jar). To my surprise i found an ObjectFactory implementation of their datasources called DB2DataSourceFactory, and inside tomcat you can just define it this way:
The DB2SimpleDataSource is not really too exciting, it doesnt provide pooling or anything else breathtaking, but for development this was perfect, i dont want to introduce problems for questions that i dont have at the moment. But if you consult the massive IBM DB2 library, you will find out that for various JDBC Types, several DataSources can be obtained. In my case i am using the Type4 Driver because i like being independent of any database client on my machine (in fact the complete DB2 is also on my devel machine, so i could also use a Type2 Driver - a pooling DataSource is only available for Type2 at the moment from IBM).
The beautiful thing about the db2jcc.jar (universal driver) is that you can connect with Type2 and Type4 with the same driver, the JDBC URL defines the Type at the end. Another cool thing is that you can connect to various DB2s with this driver, so there is no problem using it with DB2 on iSeries or DB2 on z/OS.
But we are in IBM land, you can also use the iSeries based JTopen library, that API ships another JDBC driver for connecting to the DB2 for iSeries. In fact this one also has a pooling DataSource implemenation, but when you think you can easily plug that into Tomcat, you are wrong. The JTOpen Team doesnt provide (and it was impossible to convince them otherwise some months ago) a ObjectFactory that you can define the DataSource as a JNDI resource in Tomcat. I wrote one myself (really wasnt that hard) and so it turns out that this is another neat option to connect to a DB2.
I dont know if i like having many options for one problem. At least not when it comes to JDBC drivers and DataSources from one Company. Perhaps they should streamline all their projects, but its IBM and they have a lof of platforms, perhaps it must be this way.
At the end, i really much like Tomcat5, it feels a lot better than 4. Even if its hip to bash tomcat in one or another way these days, i like that piece of software.