java - Connection with MySql is being aborted automatically. How to configure Connector/J properly? -


i read advice error message:

you should consider either expiring and/or testing connection validity before use in application, increasing server configured values client timeouts, or using connector/j connection property 'autoreconnect=true' avoid problem.

i'm using spring , jpa. should configure connector/j? (in persistence.xml, or in entitymanagerfactory spring configuration, or in datesource spring configuration, or somewhere else?)

the text describes 3 solutions prevent connection aborts:

  1. configure connection string autoreconnect=true. property of url connection string, works @ driver level. need change connection string in data source configuration.

    url="jdbc:mysql://localhost:3306/confluence?autoreconnect=true" 
  2. increase timeout. property of database. can increase value see if less connection abort.

  3. configure connection pool test connection validatiy. done @ pool, not driver level. depend on data source implementation use. should configurable in property of data source, if use pooled one, e.g. c3p0.

additionnal comments:

  • the datasource/pool can have timeout, corresponds time idle connection remains in pool. not confused db timeout.
  • there several way test validity of connection. 1 common way have dummy test table. pool issue select on dummy test table see if connection still ok.

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -