Troubleshooting database access
zero.data.
zero.data and is
not comprehensive. Although a best effort will be made to add solutions and
workarounds as they are encountered, you should rely primarily on your
database vendor's official documentation.
DB2
Obtaining DB2
If you do not already have a DB2 license, there is a "community" version, DB2 Express-C, that is available for with a free license to develop, deploy, and distribute. Make sure you use the most recent drivers for your DB2 version.
Configuration
/config/db/mydb = {
"class" : "com.ibm.db2.jcc.DB2SimpleDataSource",
"driverType" : 4,
"serverName" : "localhost",
"portNumber" : 50000,
"databaseName" : "MYDBNAME",
"user" : "someuser",
"password" : "<xor>Lz4sLCgwLTs="
}
For complete details about the valid properties for DB2 DataSource
implementations, see the DB2 Documentation. By default, driverType is 2, which
is the native CLI wrapper. Unless you have your jars and dlls all set up
correctly, it can be a pain to debug exactly why you aren't getting a
Connection. By setting to 4, the pure Java driver, you'll have better success.
For more information about selecting the appropriate DB2 DataSource
implementation, see the DB2 Documentation. If you face any issues, look below
for workarounds or post to the forum.
Configure tracing on DB2
DB2 DataSource implementations conveniently allow the setting of the trace
file on the DataSource. As such, you can configure the driver to trace file
by simply adding a property in zero.config:
/config/db/mydb = {
"class" : "com.ibm.db2.jcc.DB2DataSource",
...
"traceFile" : "${appname}/logs/db.txt"
}
In this example, ${appname} should be replaced by your application name from the
application's ivy.xml. For instance, if your application is named myapp, you
would use ${myapp}. Of course, the traceFile property can always be a hardcoded
value. C:/db/logs/db-trace, for instance. But using the variable allows for
better portability.
Throughput is slow on DB2
By default, DB2 activates and deactivates a database on demand when connections are made. Thus, with short-lived connections, as IBM® WebSphere® sMash, under some situations, you may see a significant decrease in performance and throughput because the database is being activated and deactivated upon each connection open and close.
In testing, performance increase was discovered by issuing a CONNECT TO. This caused a connection to persist for the lifetime of the Command Line Processor's session, for when the DB2 user logged off, decreased performance resumed.
Rather, database administrators can use ACTIVATE DATABASE to start up specific databases. This eliminates any application time spent on database initialization.
Consult DB2's documentation on ACTIVATE DATABASE for more usage information. Specifically, look at the "Usage notes" on the behavior of this command when the database server is stopped and restarted.
Activating databases on OS startup
You might find it useful, if your environment requires it, to activate DB2 databases when the operating system starts. To do this, you can create a startup script that executes DB2 Command Line Processor commands.
For instance, the following System V-style startup script has been successfully tested on Ubuntu 7.10:
#!/bin/bash ################################################### ####Startup script for activating DB2 databases ### ################################################### USER=db2inst1 case "$1" in start) /bin/su - $USER -c "db2 activate db emp_db" ;; stop) /bin/su - $USER -c "db2 deactivate db emp_db" ;; restart|force-reload) /bin/su - $USER -c "db2 deactivate db emp_db" /bin/su - $USER -c "db2 activate db emp_db" ;; *) exit 1 ;; esac exit 0
Replace the database name with your own. If your DB2 user is different, replace
the USER value. Save this script in a file under the /etc/init.d/ directory.
Let's say you called it dbactivate. Issue the following commands to have
the script run at system start up:
$ chmod +x /etc/init.d/dbactivate $ update-rc.d dbactivate defaults
You can issue start, stop and restart commands:
$ /etc/init.d/dbactivate start $ /etc/init.d/dbactivate stop $ /etc/init.d/dbactivate restart
Apache Derby
Configuration
Embedded Mode
/config/db/mydb = {
"class" : "org.apache.derby.jdbc.EmbeddedDataSource",
"databaseName" : "db/customer",
"createDatabase" : "create"
}
Although it is convenient to have Derby automatically create the database file system upon first connection using the createDatabase set to create, it can get very confusing when tables don't exist because the working directory has changed and the database 'successfully' connects.
Network Mode
/config/db/mydb = {
"class" : "org.apache.derby.jdbc.ClientDataSource",
"databaseName" : "db/customer",
"user" : "someuser",
"password" : "secretpassword",
"createDatabase" : "create"
}
The same 'gotcha' for Embedded Mode described above using createDatabase holds true for Network mode as well.
Issues
Derby has two 'modes': Embedded and Network. Derby always runs in a JVM, it just depends on where.
Embedded Mode
As you can probably guess, Embedded mode is running in the same JVM as
IBM® WebSphere® sMash. This is convenient, but has some 'gotchas'. For instance,
Derby locks the file system where data is persisted to disk. As such, if
WebSphere sMash is running and has established a connection in Embedded mode,
the Embedded Derby engine is running and will prevent other Derby tools from
talking to the database. When in Embedded mode, the Derby databaseName property
is the file system path to your database relative to your WebSphere sMash
application. So, db/mydb would be under ` %approot%/db/mydb.
Network Mode
Running in Network mode requires one more step, just like every other database
'server', but Network mode requires starting a Java process. This is possible
with the Derby Eclipse Plugin or from the command line. The Eclipse Plugin makes
it possible to start the network process by right clicking on a project. When
this is done, the Derby databaseName property is the same as Embedded mode,
relative to the application root. However, when the command line option is used
(%derby_home%/frameworks/NetworkServer/bin/startNetworkServer.bat), beware that
the databaseName property is relative to the working directory (i.e. where you
execute startNetworkServer.bat from). To simplify things, it might be wise to
put the directory where this batch file lives on the system path and execute it
from the application root.
Configure the Derby Trace File
Derby configures its trace file through Java System Properties. This can be accomplished by setting the properties on the command line. Derby documentation has more details. The trace file can also be set on the DataSource by setting the following properties in zero.config:
/config/db/mydb = {
"class" : "org.apache.derby.jdbc.ClientDataSource",
...
"traceFile" : "${appname}/logs/db.txt"
}
MySQL
Configuration
The following configuration is known to work with MySQL 5.0.45 on the Connector/J 5.0 drivers:
/config/db/mydb = {
"class" : "com.mysql.jdbc.jdbc2.optional.MysqlDataSource",
"serverName" : "db.example.org",
"portNumber" : 3306,
"databaseName" : "voting",
"user" : "someuser",
"password" : "secretpasssword"
}
For more information on available MysqlDataSource properties, see the complete MySQL DataSource Documentation. Downloads:
Oracle
Performance issues making connections
Oracle's oracle.jdbc.pool.OracleDataSource implementation of the
javax.sql.DataSource interface contains connection pooling built right in.
Thus, they assume everybody will use connection pooling, which WebSphere sMash
does not provide out of the box. Because of this assumption,
OracleDataSource justifies expensive methods calls to Java's cryptography
library. This can result in long connections to the database as compared to
other vendors.
The behavior of zero.data.Manager's methods is to
obtain a connection, use it, and call the close method (unless methods are
executed under the inTransaction() method or a java.sql.Connection is
passed into the zero.data.Manager constructor).