Just a thought...
Can't you just use the isClosed method to figure out whether the connection
is still open and then act accordingly?
> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Andy
> C
> Sent: Tuesday, June 13, 2000 1:29 PM
> To: [EMAIL PROTECTED]
> Subject: Second Call: Re-Connecting to database after network problem.
>
>
> 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 (for 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 I make 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 sort of query using Result Set and Statement. Its during
> this point that
> the class will throw an exception if the connection is lost.
> I need to
> reconnect it here.*/
>
>
>
>
> 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
>
___________________________________________________________________________
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