| Utility for querying object from a database. Allocates connections from
the database connection pool, ensures the integrity of those
connections, and manages result sets after a
query is performed. Returns objects representing
data in the database.
Example - querying a user:
import org.enhydra.dods.DODS;
import com.lutris.appserver.server.sql.*;
DBQuery dbQuery =
DODS.getDatabaseManager().createQuery(DATABASE_NAME);
// NOTE: class CustomerQuery implements Query { ... }
CustomerQuery
customerQuery = new CustomerQuery();
String [] loginIds = { "customer1", "customer2" };
try {
for (int idx=0; idx < loginIds.length; idx++) {
customerQuery.setQueryLoginId(loginIds[idx]);
dbQuery.query(customerQuery); // query the database
// Print all query results.
CustomerDO customerResult;
while ((customerResult =
(CustomerDO)dbQuery.next()) != null) {
System.out.println("Customer name for " +
loginIds[idx] +
" is " + customerResult.getName());
}
}
}
finally {
//
// Return database connections used by
// this object back to the connection pool
// and free any other resources consumed
// by this object.
//
dbQuery.release();
}
author: Kyle Clark since: LBS1.8 version: $Revision: 1.1 $ |