caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

JSP page
Config
URLs
Database Forms
XTP Copy
Hello Tag
Vary Filter
HardCore
Mailing Forms
Beans
Cache
XSL Filter
run-at

Database Config
 Database Configuration

Database Forms
Database Forms
XTP Copy

Resin's database configuration pulls configuration out of your application and into the configuration files where it belongs. The configuration lets you create any number of named database pools.

resin.conf
<caucho.com>

<resource-ref>
  <res-ref-name>jdbc/test_db</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <init-param driver-name="org.gjt.mm.mysql.Driver"/>
  <init-param url="jdbc:mysql://localhost:3306/test"/>
  <init-param user="ferg"/>
  <init-param password="changeit"/>
</resource-ref>

</caucho.com>

The resource-ref configuration is more general than just configuring database pools. So it needs res-type of javax.sql.DataSource to say that it's configuring a database pool and not, say, an imap client.

Since the database configuration puts the initialized pool in a JNDI Context, the resource-ref needs to specify where in the JNDI tree the data source belongs. res-ref-name tells Resin where to put the data source in the JNDI tree. The previous example used InitialContext().lookup("...") to grab the data source from the tree. Although JNDI is slightly more complicated, using it means your code can be independent of the database configuration.

Configuration Tags
resource-refthe standard configuration for data sources. (It can also be used to initialize other beans.)
res-ref-namewhere to attach the data source in the JNDI namespace. In the example, the final name will be java:comp/env/jdbc/test_db.
res-typeThe type of the resource we're configuring. In this case, we're configuring a database pool, so the resource type is javax.sql.DataSource.
init-paramLets you configure the database pool and configure arbitrary properties of the JDBC driver. Any bean setter can be used. So driver-name translates into setDriverName. You can look at com.caucho.sql.DBPool for the list of bean attributes in the pooling driver.
driver-nameSets DBPool.setDriverName. Selects the Java class of the JDBC driver. You'll need to look at your driver's documentation for the class name.
urlSets DBPool.setURL. Selects the JDBC URL for the datasource. Again, you'll need to look at your driver's documentation for this value.
userthe name of the database user
passwordthe database password

Some JDBC drivers may need additional properties, and others don't need the user and password configuration. You can look at com.caucho.sql.DBPool for the list of pooling attributes and consult your JDBC driver documentation.

Any property can be configured with the init-param entries. The parameter name is converted to a setXXX method using standard bean conventions. If the setXXX is not in the pool, the resource-ref configuration will call setProperty to set any driver property. When Resin calls setProperty, it passes the exact key given in the init-param element, without bean translations.

Classpath

You will need to add your JDBC driver to the classpath before starting Resin. There are several methods:

  1. Add the driver to the CLASSPATH environment variable.
  2. Start Resin with a -classpath argument including the driver.
  3. Put the jar file in resin-2.0.x/lib.

You can see the classpath Resin is using by starting it with the -verbose option:

unix> httpd.sh -verbose


Database Forms
Database Forms
XTP Copy
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.