Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.databases > #190 > unrolled thread

MySQL connection problems

Started by"Hakan" <hakan@THRWHITE.remove-dii-this>
First post2011-04-27 15:22 +0000
Last post2011-04-27 15:22 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.databases


Contents

  MySQL connection problems "Hakan" <hakan@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
    Re: MySQL connection prob "=?ISO-8859-1?Q?Arne_Vajh=" <=?iso-8859-1?q?arne_vajh=@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
    Re: MySQL connection prob joeNOSPAM@BEA.com.remove-dii-this - 2011-04-27 15:22 +0000
      Re: MySQL connection prob "Hakan" <hakan@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000
    Re: MySQL connection prob "David Harper" <david.harper@THRWHITE.remove-dii-this> - 2011-04-27 15:22 +0000

#190 — MySQL connection problems

From"Hakan" <hakan@THRWHITE.remove-dii-this>
Date2011-04-27 15:22 +0000
SubjectMySQL connection problems
Message-ID<1213985055.63@user.newsoffice.de>
  To: comp.lang.java.databases

 My web start application connects to a MySQL database through a 
servlet. The servlet accesses the database through a MySQL connector 
instance and returns the results the client if necessary. Everything is 
done through a Tomcat Linux web server.

 My problems seem to occur when I run the program through the servlet 
for the first time after a while, like the first time of the day or 
after not testing it on the server for some days. It can't fetch 
anything from the database, so the client just gets null objects back. 
Ultimately, a NullPointerException kills the application as it has 
nothing to work with.

 The solution is very simple. I shut down Tomcat and restart it, after 
which it again reads results from the database as it should. This is 
just not a sustainable way to deal with it.

My employer wants to deploy it such that many different users will have 
an interest in accessing it from various places and not just people with 
system administrator privileges. Hence, crashes are liable to make them 
spurn the application. That would make quite a lot of work useless.

 Do you know the source of the mentioned problem?

 Regards.

-- 
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet 
Die Signatur lE#t sich nach Belieben anpassen ;-)

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#191 — Re: MySQL connection prob

From"=?ISO-8859-1?Q?Arne_Vajh=" <=?iso-8859-1?q?arne_vajh=@THRWHITE.remove-dii-this>
Date2011-04-27 15:22 +0000
SubjectRe: MySQL connection prob
Message-ID<485c3a37$0$90266$14726298@news.sunsite.dk>
In reply to#190
  To: comp.lang.java.databases
Hakan wrote:
> My web start application connects to a MySQL database through a servlet. 
> The servlet accesses the database through a MySQL connector instance and 
> returns the results the client if necessary. Everything is done through 
> a Tomcat Linux web server.
> 
> My problems seem to occur when I run the program through the servlet for 
> the first time after a while, like the first time of the day or after 
> not testing it on the server for some days. It can't fetch anything from 
> the database, so the client just gets null objects back. Ultimately, a 
> NullPointerException kills the application as it has nothing to work with.
> 
> The solution is very simple. I shut down Tomcat and restart it, after 
> which it again reads results from the database as it should. This is 
> just not a sustainable way to deal with it.
> 
> My employer wants to deploy it such that many different users will have 
> an interest in accessing it from various places and not just people with 
> system administrator privileges. Hence, crashes are liable to make them 
> spurn the application. That would make quite a lot of work useless.
> 
> Do you know the source of the mentioned problem?

The most likely cause is a bug in your code related to
some state being kept between invocations.

Arne

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#192 — Re: MySQL connection prob

FromjoeNOSPAM@BEA.com.remove-dii-this
Date2011-04-27 15:22 +0000
SubjectRe: MySQL connection prob
Message-ID<3cc7bb54-29ef-4a69-a89d-31830003e9e3@s21g2000prm.googlegroups.com>
In reply to#190
  To: comp.lang.java.databases
On Jun 20, 11:04 am, Hakan <H...@softhome.net> wrote:
>  My web start application connects to a MySQL database through a
> servlet. The servlet accesses the database through a MySQL connector
> instance and returns the results the client if necessary. Everything is
> done through a Tomcat Linux web server.
>
>  My problems seem to occur when I run the program through the servlet
> for the first time after a while, like the first time of the day or
> after not testing it on the server for some days. It can't fetch
> anything from the database, so the client just gets null objects back.
> Ultimately, a NullPointerException kills the application as it has
> nothing to work with.
>
>  The solution is very simple. I shut down Tomcat and restart it, after
> which it again reads results from the database as it should. This is
> just not a sustainable way to deal with it.
>
> My employer wants to deploy it such that many different users will have
> an interest in accessing it from various places and not just people with
> system administrator privileges. Hence, crashes are liable to make them
> spurn the application. That would make quite a lot of work useless.
>
>  Do you know the source of the mentioned problem?
>
>  Regards.
>
> --
> Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet
> Die Signatur l=E4=DFt sich nach Belieben anpassen ;-)

I'm guessing the 'connector' has a simple JDBC connection underneath,
which is killed after a time of idleness, perhaps by a firewall or
a DBMS setting for idle sessions. One simple hack would be to store
each successful time-of-use in the servlet, and at each invoke,
compare the current time to the last successful use, and if it
hasn't been used for an hour (experiment to find the right value)
you must re-create connector. I'd see about the DBMS parameters
that might be killing the connection out from under you.
HTH,
Joe Weinstein at Oracle

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#193 — Re: MySQL connection prob

From"Hakan" <hakan@THRWHITE.remove-dii-this>
Date2011-04-27 15:22 +0000
SubjectRe: MySQL connection prob
Message-ID<1214039638.87@user.newsoffice.de>
In reply to#192
  To: comp.lang.java.databases
joeNOSPAM@BEA.com wrote:


> I'm guessing the 'connector' has a simple JDBC connection underneath,
> which is killed after a time of idleness, perhaps by a firewall or
> a DBMS setting for idle sessions. One simple hack would be to store
> each successful time-of-use in the servlet, and at each invoke,
> compare the current time to the last successful use, and if it
> hasn't been used for an hour (experiment to find the right value)
> you must re-create connector. I'd see about the DBMS parameters
> that might be killing the connection out from under you.
> HTH,
> Joe Weinstein at Oracle

 You are right that I had missed to close the MySQL driver connection. I 
have now added close statements whenever I exit the application in the 
code and a shutdown hook closing the database driver connection on 
unvoluntary shutdowns. Thank you for your help.

-- 
Newsoffice.de - Die Onlinesoftware zum Lesen und Schreiben im Usenet 
Die Signatur lE#t sich nach Belieben anpassen ;-)

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#194 — Re: MySQL connection prob

From"David Harper" <david.harper@THRWHITE.remove-dii-this>
Date2011-04-27 15:22 +0000
SubjectRe: MySQL connection prob
Message-ID<b047k.13142$E41.1537@text.news.virginmedia.com>
In reply to#190
  To: comp.lang.java.databases
Hakan wrote:
> 
> My web start application connects to a MySQL database through a servlet. 
> The servlet accesses the database through a MySQL connector instance and 
> returns the results the client if necessary. Everything is done through 
> a Tomcat Linux web server.
> 
> My problems seem to occur when I run the program through the servlet for 
> the first time after a while, like the first time of the day or after 
> not testing it on the server for some days. It can't fetch anything from 
> the database, so the client just gets null objects back. Ultimately, a 
> NullPointerException kills the application as it has nothing to work with.
> 
> The solution is very simple. I shut down Tomcat and restart it, after 
> which it again reads results from the database as it should. This is 
> just not a sustainable way to deal with it.
> 
> My employer wants to deploy it such that many different users will have 
> an interest in accessing it from various places and not just people with 
> system administrator privileges. Hence, crashes are liable to make them 
> spurn the application. That would make quite a lot of work useless.
> 
> Do you know the source of the mentioned problem?
> 
> Regards.

The MySQL server has a system variable named wait_timeout:

http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#option_mysqld_wait_timeout

If there is no activity on a TCP/IP connection for more than 
wait_timeout seconds, then the server will close the connection.

The default value is 28800 seconds, or 8 hours.

You can either override the timeout globally in your server 
configuration file by adding a line such as

wait_timeout = 864000

to change the timeout to 10 days for all connections, or set it on a 
per-connection basis by sending the command

   set wait_timeout = 864000;

to the server from each new connection.

David Harper
Cambridge, England

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.databases


csiph-web