db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oyvind.Bakk...@Sun.COM
Subject Re: I need some advice to choose database for an upcomming job
Date Mon, 07 Nov 2005 11:47:59 GMT
Legolas Woodland wrote:
> Hi
> Thank you for the Blog entry ,
> but i could not understand how i should do the integration based on your 
> blog comment.
> I tried Integration senario from developerWorks ,
> I need it for a real world high transaction system (23-30 Tra / second) 
> so i think developersWork scenario is not good for me.
> can you explain more pleas ? (to Oyvind Bakksjo)

You should be able to fully embed Derby into your web application 
without any need to configure your servlet container *and* get decent 
performance by doing the following:
* Place derby.jar in your web application's lib directory.
* Use derby in embedded mode inside your application (use 
"jdbc:derby:<dbname>[;attributes...]" as the connection url)
* For performance, you need to avoid creating a new connection with each 
request. Therefore, you should a) boot the database when your web 
application is loaded (and shut it down when the web app is unloaded) 
and b) reuse existing connection(s).
* To do a)
   - create a class in your web app which implements the 
javax.servlet.ServletContextListener interface (see 
The class should have a public no-arg constructor. Say, the class is 
called MyListener.
   - Inside the <web-app> section of your deployment descriptor, add 
   - The class must implement two methods. In contextInitialized(), you 
boot the database by getting a connection to it (possibly with 
";create=true", if necessary). Stuff that connection aside for later use 
by calling 'sce.getServletContext().setAttribute("derbyconnection", 
connection);'. In contextDestroyed, fetch the existing connection (with 
'sce.getServletContext().getAttribute("derbyconnection");') and close 
that connection. Shut down the database by connecting again with the 
"shutdown=true" attribute in the url.
* To do b)
   - When a request is received (say, HttpServlet.doGet() is invoked), 
you get the existing connection by calling 
'getServletContext().getAttribute("derbyconnection");'. Use this 
connection for your database work.

Note A: You may want to create and use more than one connection to 
increase performance if you have many simultaneous requests.
Note B: If you're running with autocommit OFF, you should definately not 
use the same connection object in multiple simultaneous requests (either 
use synchronization or create multiple connections).

I hope this helps.

Oyvind Bakksjo
Sun Microsystems, Database Technology Group
Trondheim, Norway

View raw message