I've had a Servlet connected to a SQL 7 database for around
18 months now at:

http://www.r2-dvd.org

Currently the webserver (JWS2.0) is on one machine and the sql server
on another that are in the same physical location and on the same ethernet
switch.  However I need  (fro policital reasons) to move the webserver to
another location (around 600 miles away) where it will be on a completely
different network seperated from the sql server by many IP Routers.

During testing I noticed that the servle would often lose connection to the
sql server and only reloading the servlet will reconnect it.

The question is, how do Imake the servlet re-connect to the database should
the original connection be lost. ?

The code is something like

public class DBDirect extends HttpServlet {
Stack Connections = null;
boolean addConnections(){
 try{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 }catch(Exception E){
  System.out.println("Can Not Load to drivert: " + E);
 }
 Connections = new Stack();
 int x=0;
 System.out.println("*-----------------------------------------*");
 System.out.println("*--------------  Opening -----------------*");
 System.out.println("*----------- Connections -----------------*");
 System.out.println("*-----------------------------------------*");

   try {
      for( x=0; x<10; x++){

Connections.push(DriverManager.getConnection("jdbc:odbc:DVD-List","sa","") )
;
         System.out.println("Connection created :"+x);
      }
   }
   catch(SQLException E) {
      System.out.println("Connection Error at :"+x+" E= " + E);
// E.printStackTrace();
      Connections = null;
   return false;
   }
ServletConfig Config;

public void init(ServletConfig config) throws ServletException{
 super.init(config);
 this.Config=config;

   addConnections() ;

}




public void service(HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException{

     Addr=req.getRemoteAddr();
 System.out.println("DBDirect Entering service:" +Addr);

     try {
        if ( Connections.empty() == true){
           System.out.println("Out of connections, waiting" +Addr);
           wait();
        }
     }
     catch( InterruptedException E){
         System.out.println("Interrupted error");

     }


//Do some query on the connection using}



Many Thanks
Andy C

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to