Tuesday, December 05, 2006

Using MySQL5 with NetBeans5.5 and Sun Java System AS 9.0u1

I've been using NetBeans 5.5 a lot lately, and I must say I like it and have decided to stick with it. NetBeans comes bundled with the Sun Java System Application Server, another product I have come to appreciate lately. These two are are the latest additions to my arsenal of development tools, alongside Eclipse and JBoss AS. I've all but dumped JBuilder (they are moving to an Eclipse base anyway).
The SJAS comes bundled with JavaDB, and open-source Java database. It's great I suppose, but without a management console, it hasn't been easy to use. So I'm switching to MySQL. The following steps are for setting up MySQL in SJSAS, and developing applications in NetBeans that'll use it.
  1. Ensure that the NetBeans 5.5 and Sun Java System AS 9u1 setup works, as in, you've done deployments to the server from the IDE. In NetBeans, you should be able to monitor and control the server from the Runtime view. You should also be able to debug easily on the server from NetBeans.
  2. Download the MySQL database driver for JDBC (Connector/J). Extract the JAR file to domains\domain1\lib\ext. In that location, it'll be included in the application server's classpath.
  3. Download and install MySql 5.0 and install it on your machine. I set mine to run as a service (though not at start up). Most defaults worked fine.
  4. Download and install MySQL Tools (which includes an administrative console). I used this to create a schema for development use (in Microsoft's world, these would be "databases").
  5. Open the web-based SJSAS console. Go to Resources -> JDBC -> Connection Pools -> New ... Provide a name, use the connection pool datasource for resource type and select mysql for vendor. Datasource class name = com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource. Add properties - user, password, server, schema (created in step #4), and port.
  6. Go to Resources -> JDBC -> JDBC Resources -> New ... to create a JNDI resource. Its name should start with jdbc/someName. Select the connection pool created in #5. If it starts without error, #2 is confirmed and you are on your way.

No comments: