JSP, Connecting to SQL throws exception

Discussion in 'Java' started by Ghost, Aug 19, 2005.

  1. Ghost

    Ghost Guest

    I have a server that is hosting one of my websites. The website
    consists of servlets, JSPs and HTML. When a user logs in to the
    website, a servlet will query the SQL database to see if the username
    and password exist in the database.

    I can deploy this website by logging into the tomcat manager and
    providing my .war file. When I do this, everything is fine. Users can
    log in and log out all day long.

    Here is my problem:
    If I deploy the website today, users can log in and log out all day.
    Tomorrow when a user goes to log in, the sql query to see if the
    username and password exist in the SQL database throw the following
    exception:
    // My Website Log File:
    [09:15:51,066] (VerifyLogin.java ) DEBUG - caught sql exception:
    Communications link failure due to underlying exception:

    ** BEGIN NESTED EXCEPTION **

    java.net.SocketException
    MESSAGE: Software caused connection abort: recv failed

    STACKTRACE:

    java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at
    com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:104)
    at
    com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:144)
    at
    com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:172)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1839)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2288)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2788)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2379)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
    at com.mysql.jdbc.Statement.executeQuery(Statement.java:1192)
    at com.cognitronics.servlets.VerifyLogin.doGet(VerifyLogin.java:94)
    at com.cognitronics.servlets.VerifyLogin.doPost(VerifyLogin.java:136)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    at
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482)
    at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    at
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    at
    org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    at
    org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    at java.lang.Thread.run(Unknown Source)


    Does anyone know what might be going on here? Every morning that I
    come in, I have to re-deploy the website.

    Any advice would be greatly appreciated. Thanks in advance.
     
    Ghost, Aug 19, 2005
    #1
    1. Advertising

  2. Ghost

    Jeff Zhao Guest

    I think your some codes are wrong.Maybe you haven't get the connection
    because the all connections have been running.
     
    Jeff Zhao, Aug 19, 2005
    #2
    1. Advertising

  3. Ghost

    Malte Guest

    Ghost wrote:

    First of all, your sql probably needs to be more robust, ie after
    checking the connection you might want to be prepared to reestablish the
    connection if need be.

    Second, I have seen cases where a timeout causes (especially Oracle
    connections) to go lost. This might also be the case when the firewall
    cuts off on port 1521 after one hour. Since this happens for you during
    (possible) slow hours, it seems reasonable to assume this is the case.

    For these events I usually use a Singleton pattern for the connection
    pool, check for SQL connection errors and re-initialize the pool when
    necessary.

    If this is indeed a timing issue, you can have the server query the
    database every 30 minutes (select sysdate or some such) to keep the
    connection alive.
     
    Malte, Aug 19, 2005
    #3
  4. Ghost

    Roedy Green Guest

    On 19 Aug 2005 06:37:43 -0700, "Ghost" <> wrote
    or quoted :

    >at com.mysql.jdbc.Connection.execSQL(Connection.java:2379)


    Just guessing here. But, are connections supposed to survive for days
    at a time? Do they time out after X minutes of inactivity? Are
    connections supposed to survive a database reorg or backup?

    Perhaps what is needed is some code to catch an exception when the
    connection breaks and reestablish it.

    Perhaps you need to keep some dummy traffic going to maintain the
    connection.

    Put these ideas low in priority. They are just wild guesses in case
    you don't get better solutions.
     
    Roedy Green, Aug 20, 2005
    #4
  5. Roedy Green wrote:
    > On 19 Aug 2005 06:37:43 -0700, "Ghost" <> wrote
    > or quoted :
    >
    >
    >>at com.mysql.jdbc.Connection.execSQL(Connection.java:2379)

    >
    >
    > Just guessing here. But, are connections supposed to survive for days
    > at a time? Do they time out after X minutes of inactivity? Are
    > connections supposed to survive a database reorg or backup?
    >
    > Perhaps what is needed is some code to catch an exception when the
    > connection breaks and reestablish it.
    >
    > Perhaps you need to keep some dummy traffic going to maintain the
    > connection.


    Better yet, use a connection pool. Your JSP container should already
    have an implementation.

    >
    > Put these ideas low in priority. They are just wild guesses in case
    > you don't get better solutions.


    HTH,
    Ray

    --
    XML is the programmer's duct tape.
     
    Raymond DeCampo, Aug 20, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Miller
    Replies:
    4
    Views:
    13,578
    Chris Smith
    Nov 22, 2003
  2. Replies:
    0
    Views:
    4,548
  3. Harperator
    Replies:
    1
    Views:
    1,422
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Feb 25, 2007
  4. =?Utf-8?B?TmVpbCBQYWRkb2Nr?=

    Connecting to SQL 2000 database with SQL 2005 tools installed

    =?Utf-8?B?TmVpbCBQYWRkb2Nr?=, May 2, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    422
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    May 2, 2007
  5. Replies:
    2
    Views:
    358
Loading...

Share This Page