How to register a connection to a database with a JNDI name and use the JNDI name specified?

Nick Maiorano

First, let's say that the way in which you do this will vary depending on whether you are using an Entity Bean or a Session Bean.

The way in which you access your database from an Application Server is vendor specific.
Usually, you define a connection by specifying a JDBCdriver in your Application Server's config file. You supply the driver along with a user/password to your database (although this too is database and driver specific). Once you've done this, your Application Server will automatically register the connection in JNDI and possibly create a pool of connections.
With Entity Beans, you can define which connection you wish to use inside the deployment descriptor. With Session Beans using JDBC, you lookup the name of the connection you've configured with JNDI.

Since much of this is really Application Server dependant, I recommend you look at sample code from your Application Server vendor.
Vendors, in fact, usually include basic examples for stuff like this.