Why dont you put your resource - say, the ConnectionBroker (if u r using
one) - in the ServletContext so that it always has a reference to it and
thus wont get garbage collected ?
----- Original Message -----
From: Ellen Murray <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, February 24, 2001 12:23 AM
Subject: database connection getting garbage collected
> Hi,
>
> After several hours with no activity my connection
> pool
> seems to get garbage collected (or die). It works
> fine,
> but then I come in the next day and get the following
> error:
>
> java.sql.SQLException:
> Communication link failure: java.net.SocketException
>
> The full stack trace is at the bottom of the page. If
> I reload the page in question a couple of times the
> connection comes back and everything is o.k.
>
> I am working on my own so I need some help. I've
> included the data-sources section of the
> struts-config.xml file and the database related part
> of my perform method below.
>
> Any insight would be greatly appreciated.
>
> Thanks,
>
> Ellen
>
>
> file://------------------------------
> file://-- in the struts-config.xml
> file://------------------------------
> <data-sources>
> <data-source
> autoCommit="true"
> description="test-jdbc"
> driverClass="org.gjt.mm.mysql.Driver"
> maxCount="4"
> minCount="2"
> password="blahblah"
> user="blahblah"
> url="jdbc:mysql://localhost/mydb" />
> </data-sources>
>
>
>
> file://------------------------------
> file://-- in my Action class
> file://------------------------------
> public ActionForward perform(...) throws ...
>
> GenericConnection connection = null;
>
> try {
> DataSource ds = servlet.findDataSource(null);
> connection =
> (GenericConnection) ds.getConnection();
>
> String sql = "select * from mytable";
>
> Statement statement =
> connection.createStatement();
> ResultSet results =
> statement.executeQuery(sql);
>
> while (results.next()) {
> // stuff goes here
> }
> connection.close();
> results = null;
> statement = null;
> connection = null;
> }
> catch (SQLException se)
> request.setAttribute("exception", se);
> return (mapping.findForward("failure"));
> }
> finally {
> // Return connection to pool
> if (connection != null) {
> try {
> connection.close();
> }
> connection = null;
> }
> }
> }
>
>
>
> file://------------------------------
> // exception.printStackTrace()
> file://------------------------------
>
> java.sql.SQLException: Communication link failure:
> java.net.SocketException
> at java.lang.Throwable.fillInStackTrace(Native
> Method)
> at
> java.lang.Throwable.fillInStackTrace(Compiled Code)
> at java.lang.Throwable.<init>(Compiled Code)
> at java.lang.Exception.<init>(Compiled Code)
> at
> java.sql.SQLException.<init>(SQLException.java:43)
> at
> org.gjt.mm.mysql.MysqlIO.sendCommand(Compiled Code)
> at
> org.gjt.mm.mysql.MysqlIO.sqlQueryDirect(Compiled Code)
> at org.gjt.mm.mysql.MysqlIO.sqlQuery(Compiled
> Code)
> at
> org.gjt.mm.mysql.Connection.execSQL(Compiled Code)
> at
> org.gjt.mm.mysql.Connection.execSQL(Compiled Code)
> at
> org.gjt.mm.mysql.Statement.executeQuery(Compiled Code)
> at
> org.gjt.mm.mysql.jdbc2.Statement.executeQuery(Compiled
> Code)
> at planner.ShowReleasesAction.perform(Compiled
> Code)
> at
>
org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.ja
va:1634)
> at
> org.apache.struts.action.ActionServlet.process(ActionServlet.java:1444)
> at
> org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:472)
> at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
> at
> javax.servlet.http.HttpServlet.service(Compiled Code)
> at
> org.apache.tomcat.core.ServletWrapper.doService(Compiled
> Code)
> at
> org.apache.tomcat.core.Handler.service(Compiled Code)
> at
> org.apache.tomcat.core.ServletWrapper.service(Compiled
> Code)
> at
>
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
> at
> org.apache.tomcat.core.ContextManager.service(Compiled
> Code)
> at
>
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(Compi
led
> Code)
> at
> org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled
> Code)
> at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled
> Code)
> at java.lang.Thread.run(Compiled Code)
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - Buy the things you want at great prices!
http://auctions.yahoo.com/