Hi you have to use a ConnectionPool
Regards
Rinaldo Bonazzo

-----Messaggio originale-----
Da: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED] Per conto di
Jared Pace
Inviato: sabato 19 luglio 2003 0.20
A: [EMAIL PROTECTED]
Oggetto: JDBC Servlet Problems


I wrote several servlets that access a MySQL database using a single,
persistent, sychronized connection.  About eight servlets use this
connection (the code for the connection class is at the bottom of this
email, with username/password information changed).

Lately, my Tomcat server has been crashing after being up only a short
time. My webhosting company has moved me to three different servers only
to see the same thing happen at each one and has determined that it's my
servlets that are crashing Tomcat.  Other than using JDBC and the one
single connection, my servlets perform rather trivial operations.

So, my questions are:  can I use a single connection for a site that
receives around 3000 hits per day?  Is it possible that my single
connection is crashing Tomcat?  Some of the information I retrieve from
the database is very large since it's for a fan fiction site and some of
the queries retrieve stories whose data type is medium-text.  Is there
anything I need to do to buffer the response when dealing with output of
>= 32KB?  Also, I slightly modified the single connection class using
one written by my computer science professor, so I thought it was good
practice...now, I'm wondering if it's responsible for my problems.
Thanks in advance for your assistance.

Jared



import java.sql.*;

public class MySQLConnection
{
   private Connection conn;

   private MySQLConnection(){
      try {
         Class.forName("org.gjt.mm.mysql.Driver").newInstance();
         conn =
DriverManager.getConnection("jdbc:mysql://localhost/myDB",
                "username", "password");
      }

      catch (Exception e){ conn = null; }
   }

   public Connection getConnection(){
      try{
         if(conn.isClosed()){
            Class.forName("org.gjt.mm.mysql.Driver").newInstance();
            conn =
DriverManager.getConnection("jdbc:mysql://localhost/myDB",
                   "username", "password");
         }
      }

      catch (Exception e){ conn = null; }

      return conn;
   }

   // Static members and methods below.

   private static MySQLConnection theConnection =
   new MySQLConnection();

   public static synchronized MySQLConnection getInstance(){
      return theConnection;
   }
}

________________________________________________________________________
___
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

Reply via email to