![]() ![]() ![]() ![]() |
![]() |
This appendix provides information on connecting Enhydra applications to specific database types. In general, you need to add the database configuration information to the application configuration file, appName
.conf
.
Enhydra connects to databases using a JDBC driver. Enhydra has its own class loader, but the JDBC driver must be loaded by the system class loader. Therefore, it is important to specify the path to JDBC driver in your system
CLASSPATH
and not in the Enhydra application'sCLASSPATH
.A common way to do this is to save the driver in a
lib
directory in the project and define theCLASSPATH
in the start script. To do this, follow these steps:
- Create a
lib
directory in the top level of your project and copy your JDBC driver to this directory.
- Edit your application's
start
file (in theappName/appName
directory) to place the driver in yourCLASSPATH
. For example, the bold setCLASSPATH
:
echo "***"
echo "*** Connect to http://'hostname':9000/"
echo "***"CLASSPATH="../lib/classes111.zip"
export CLASSPATH
/usr/local/lutris-enhydra3.0/bin/multiserver ./multiserver.conf
- Build the project with make, which will copy the start script to the directory
appName/output
. Use this script to start your application.Be careful to keep the right driver with your application. For example, there are multiple versions of the Oracle JDBC driver,
classes111.zip
. When your application goes into production, make sure that the project administrator knows to reference the correct driver when the database is upgraded in the future.
This section presents an example of an Oracle configuration. To use this example, change the values shown in bold.
#-------------------------------------------------------------------# Database Manager Configuration
#------------------------------------------------------------------- DatabaseManager.Databases[] = "database_id"
DatabaseManager.DefaultDatabase = "database_id"
DatabaseManager.Debug = "false"
DatabaseManager.DB.database_id.ClassType = "Oracle"
DatabaseManager.DB.database_id.JdbcDriver = "oracle.jdbc.driver.OracleDriver"
DatabaseManager.DB.database_id.Connection.Url = "jdbc:oracle:thin:@server_name:1521:db_instance"
DatabaseManager.DB.database_id.Connection.User = "User"
DatabaseManager.DB.database_id.Connection.Password = "Password"
DatabaseManager.DB.database_id.Connection.MaxPreparedStatements = 10
DatabaseManager.DB.database_id.Connection.MaxPoolSize = 30
DatabaseManager.DB.database_id.Connection.AllocationTimeout = 10000
DatabaseManager.DB.database_id.Connection.Logging = false
DatabaseManager.DB.database_id.ObjectId.CacheSize = 20
DatabaseManager.DB.database_id.ObjectId.MinValue = 1
The driver used here is the Oracle thin driver, and "db_instance" is the name of the Oracle database instance.
This section presents an example of an Informix configuration. To use this example, change the values shown in bold.
#-------------------------------------------------------------------# Database Manager Configuration
#------------------------------------------------------------------- DatabaseManager.Databases[] = "database_id"
DatabaseManager.DefaultDatabase = "database_id"
DatabaseManager.Debug = "false"
DatabaseManager.DB.database_id.ClassType = "Informix"
DatabaseManager.DB.database_id.JdbcDriver = "com.informix.jdbc.IfxDriver"
DatabaseManager.DB.database_id.ConnectionURL =
jdbc:informix-sqli://<hostname>:<port#>:INFORMIXSERVER=<db_inst>;user=<user>; password=<password>
DatabaseManager.DB.database_id.Connection.user = "<user>"
DatabaseManager.DB.database_id.Connection.Password = "<password>"
DatabaseManager.DB.database_id.Connection.MaxPreparedStatements = 10
DatabaseManager.DB.database_id.Connection.MaxPoolSize = 30
DatabaseManager.DB.database_id.Connection.AllocationTimeout = 10000
DatabaseManager.DB.database_id.Connection.Logging = false
DatabaseManager.DB.database_id.objectID.CacheSize = 20
DatabaseManager.DB.database_id.MinValue = 1
This section presents an example of a Sybase configuration. To use this example, change the values shown in bold.
#-------------------------------------------------------------------# Database Manager Configuration
#------------------------------------------------------------------- DatabaseManager.Databases[] = "database_id"
DatabaseManager.DefaultDatabase = "database_id"
DatabaseManager.Debug = "true"
DatabaseManager.DB.database_id.ClassType = "Sybase"
DatabaseManager.DB.database_id.JdbcDriver = "com.sybase.jdbc2.jdbc.SybDriver"
DatabaseManager.DB.database_id.Connection.Url = "jdbc:sybase:Tds:<hostname>.sybase.com:7100"
DatabaseManager.DB.database_id.Connection.User = "name"
DatabaseManager.DB.database_id.Connection.Password = "password"
DatabaseManager.DB.database_id.Connection.MaxPoolSize = "2"
DatabaseManager.DB.database_id.Connection.AllocationTimeout = "2"
DatabaseManager.DB.database_id.Connection.Logging = "true"
DatabaseManager.DB.database_id.Connection.MaxPreparedStatements = "2"
DatabaseManager.DB.database_id.ObjectId.CacheSize = 2
DatabaseManager.DB.database_id.ObjectId.MinValue = 1
MySQL is an Open Source database that is lightweight and fast. However, it does not support transactions. Because of this, you have to make a small patch to the Enhydra code to use MySQL. For more information, see the Enhydra mailing list archive.
Because MySQL does not support transactions, and therefore does not support autocommit, you have to make a small change to the code and rebuild Enhydra. You need to change the file
com/lutris/appserver/server/sql/standard/StandardDBConnection.java
and comment out one line, as shown below:
public void setAutoCommit(boolean on) throws SQLException {validate();
logDebug("ignores set auto commit: " + on);
// connection.setAutoCommit(on);
}
You must then rebuild this Enhydra package. For details, see the Enhydra mailing list archive.
This section presents an example of a MySQL configuration. To use this example, change the values shown in bold.
#-------------------------------------------------------------------# Database Manager Configuration
#------------------------------------------------------------------- DatabaseManager.Databases[] = database_id
DatabaseManager.DefaultDatabase = database_id
DatabaseManager.Debug = true
DatabaseManager.DB.database_id.ClassType = Standard
DatabaseManager.DB.database_id.Connection.User = username
DatabaseManager.DB.database_id.Connection.Password = password
DatabaseManager.DB.database_id.Connection.MaxPoolSize = 5
DatabaseManager.DB.database_id.Connection.AllocationTimeout = 10000
DatabaseManager.DB.database_id.Connection.Logging = true
DatabaseManager.DB.database_id.ObjectId.CacheSize = 1024
DatabaseManager.DB.database_id.ObjectId.MinValue = 100
DatabaseManager.DB.database_id.JdbcDriver = org.gjt.mm.mysql.Driver
DatabaseManager.DB.database_id.Connection.Url ="jdbc:mysql://[host]:[port]/[inst]"
PostgreSQL is a popular open source database used with Enhydra. However, as explained in "Loading the Schema," DODS requires a special column named OID in each table--however OID is a reserved word in PostgreSQL. Fortunately, the column names used for OID and VERSION are configurable.
To configure these names, add the following lines to you application configuration file:
DatabaseManager.ObjectIdColumnName = "ColName_for_ObjectID"DatabaseManager.VersionColumnName = "ColName_for_Version"
where ColName_for_ObjectID and ColName_for_Version are the column names you want to use instead of OID and VERSION.
Microsoft Access is not a true SQL database server; as such, it is suitable for development and testing, but not for a production database. Access does not have a JDBC driver. However, Access does support ODBC, and there is a JDBC-ODBC bridge in the Sun JDK, which enables Access to work with Enhydra.
Since Access cannot read in files containing SQL commands, you must create tables in the Access GUI. See the Access documentation for more information. For the DiscRack example, you can also use the Access database provided in
<enhydra_root>/examples/DiscRack/discRack.mdb
.You can test the ODBC access alone using the test program in "Establishing a JDBC Connection." Use the driver and connect strings from the configuration file listed here. If you encounter problems, be sure your data values are valid.
- Register the database as an ODBC data source:
- Go to Start | Settings | Control Panel and click on ODBC Data Sources.
- Select the add button in the window that comes up.
- Select the Microsoft Access Driver in the Create New Datasource window and click Finish.
- The ODBC Microsoft Access Setup window appears. Choose a name, like discRack, for the Data Source Name. Under Database, click the Select button, browse to the
*.mdb
file, select it, and click the OK button.
- Place database information in the application's configuration file, as shown in the example below.
Note: You don't have to place the JDBC driver in the application's
CLASSPATH
, because the ODBC/JDBC bridge is in the JDK and thus is already in the system'sCLASSPATH
.This section presents an example of an Access configuration. To use this example, change the values shown in bold.
#-------------------------------------------------------------------
# Database Manager Configuration
#-------------------------------------------------------------------
DatabaseManager.Databases[] = "
database_id"
database_idDatabaseManager.DefaultDatabase = "
"
database_idDatabaseManager.Debug = "false"
DatabaseManager.DB.
.ClassType = "Standard"
database_idDatabaseManager.DB.
.JdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver"
database_idDatabaseManager.DB.
.Connection.Url = "jdbc:odbc:
discRack"
database_idDatabaseManager.DB.
.Connection.User = "Admin"
database_idDatabaseManager.DB.
.Connection.Password = ""
database_idDatabaseManager.DB.
.Connection.MaxPreparedStatements = 10
database_idDatabaseManager.DB.
.Connection.MaxPoolSize = 30
database_idDatabaseManager.DB.
.Connection.AllocationTimeout = 10000
database_idDatabaseManager.DB.
.Connection.Logging = false
database_idDatabaseManager.DB.
.ObjectId.CacheSize = 20
database_idDatabaseManager.DB.
.ObjectId.MinValue = 1
Lutris Technologies http://www.lutris.com 1200 Pacific Ave., Suite 300 Santa Cruz, CA 95060 Voice: (831) 471-9753 Fax: (831) 471-9754 documentation@lutris.com |