commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From diego.ga...@nurun.it
Subject DbUtils Best Practices
Date Wed, 12 Sep 2007 13:48:00 GMT
Hi, I'm developing a web application using DbUtils classes to execute
queries and so on.

I user QueryRunner class with a DataSource.

I red this class is thread safe, so I implemented a Singleton to instance
QueryRunner only once.

This is my code:

public class QueryManager {

 private static QueryManager queryManager = null;

 private static QueryRunner queryRunner = null;

 static {
   try {
	queryRunner = new QueryRunner(DataSourceSingleton.getInstance()
					.getDataSource());
	} catch (Exception e) {
	}
 }

 public static QueryManager getInstance() {
    if (queryManager == null) {
	queryManager = new QueryManager();
    }
    return queryManager;
 }

 public QueryRunner getQueryRunner() {
   return queryRunner;
 }

In my servlets I use:

QueryManager.getInstance().getQueryRunner().query(...);

Is this correct?

Which is the best practice to use QueryRunner in a web context?

Thanks a lot in advance


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message