Performance and scalability: Optimum way of handling Database connections

  1. Optimum way of handling Database connections (1 messages)

    Please suggest me the optimum way of handling database connections. When should i go for connections in static variables and when for instance variables. Moreover, if in case the application abnormally terminates, how to trap the event and close all the connections opened by the application?.
    Please help me.
  2. In a Web or EJB environment should avoid static variables for anything but constants. The EJB or Webcontainter should provide database connections or transaction handles via jndi or something similiar.