HOW TO : CORE
get database connections
If you don't want
to use the classes of JFW for executing a sql command or a stored
procedure, you can still use the classes that distribute database
First of all, you have to configure the jfw.properties. As you cans see in
"HOW TO : WEBAPP > jfw.properties"
you can use the JFW connection pool mechanism
or a data source defined outside the JFW, for example using the
To get a database connection, you have to use the class ConnectionBroker:
is the logical name of a database resource as is defined in the parameter
The database connection will be got from the connection pool or by
the data source and will be returned to the caller. In that way you can change dynamically the
types of your database resources, between connection pools and data
sources, without changing the code.
For releasing the connection, you have to do this:
object passed to the method release
is the one
previously returned by
If you want to make a database transaction, you can use the class
To create a transaction for the default database resource, you can use the constructor
with no parameters; if you want to use a different database resource
you have to use the other constructor.
The method getConnection
returns a Connection
The returned connection is always the same.
When you have finished the transaction, you can use the method close
boolean parameter is used to make the commit
) or the rollback
) before the connection is released.
Here is a typical use of the Transaction