MySql connection exception solved

Source: Internet
Author: User

MySql connection exception solved

In the past two days, I encountered a problem connecting to mysql. I haven't completed the problem after finding someone for several days. Let's take a look at the error message first:

========================================================== ======================================

Org. springframework. transaction. CannotCreateTransactionException: cocould not open Hibernate Session for transaction; nested exception is org. hibernate. exception. JDBCConnectionException: Cannot open connection

At org. springframework. orm. hibernate3.HibernateTransactionManager. doBegin (HibernateTransactionManager. java: 596)

At org. springframework. transaction. support. AbstractPlatformTransactionManager. getTransaction (AbstractPlatformTransactionManager. java: 371)

At org. springframework. transaction. interceptor. TransactionAspectSupport. createTransactionIfNecessary (TransactionAspectSupport. java: 334)

At org. springframework. transaction. interceptor. TransactionInterceptor. invoke (TransactionInterceptor. java: 105)

At org. springframework. aop. framework. ReflectiveMethodInvocation. proceed (ReflectiveMethodInvocation. java: 172)

At org. springframework. aop. framework. Cglib2AopProxy $ DynamicAdvisedInterceptor. intercept (Cglib2AopProxy. java: 622)

At hitec. dms. element. service. biz. impl. DmsMonitorThreadServiceImpl $ EnhancerByCGLIB $ a293fc8f. findList (<generated>)

At hitec. influence. platform. quartz. ThreadListener. monitorThread (ThreadListener. java: 117)

At hitec. influence. platform. quartz. job. GatherJob. process (GatherJob. java: 12)

At hitec.influence.platform.quartz.quartzdispatcher$zjob.exe cute (QuartzDispatcher. java: 377)

At org. quartz. core. JobRunShell. run (JobRunShell. java: 202)

At org. quartz. simpl. SimpleThreadPool $ WorkerThread. run (SimpleThreadPool. java: 525) Caused by: org. hibernate. exception. JDBCConnectionException: Cannot open connection

At org. hibernate. exception. SQLStateConverter. convert (SQLStateConverter. java: 97)

At org. hibernate. exception. JDBCExceptionHelper. convert (JDBCExceptionHelper. java: 66)

At org. hibernate. exception. JDBCExceptionHelper. convert (JDBCExceptionHelper. java: 52)

At org. hibernate. jdbc. ConnectionManager. openConnection (ConnectionManager. java: 449)

At org. hibernate. jdbc. ConnectionManager. getConnection (ConnectionManager. java: 167)

At org. hibernate. jdbc. JDBCContext. connection (JDBCContext. java: 142)

At org. hibernate. transaction. JDBCTransaction. begin (JDBCTransaction. java: 85)

At org. hibernate. impl. SessionImpl. beginTransaction (SessionImpl. java: 1354)

At org. springframework. orm. hibernate3.HibernateTransactionManager. doBegin (HibernateTransactionManager. java: 555)

... 11 more Caused by: com. mysql. jdbc. exceptions. jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not supported Ed any packets from the server.

At sun. reflect. GeneratedConstructorAccessor248.newInstance (Unknown Source)

At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)

At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)

At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)

At com. mysql. jdbc. SQLError. createCommunicationsException (SQLError. java: 1117)

At com. mysql. jdbc. MysqlIO. <init> (MysqlIO. java: 350)

At com. mysql. jdbc. ConnectionImpl. coreConnect (ConnectionImpl. java: 2393)

At com. mysql. jdbc. ConnectionImpl. connectOneTryOnly (ConnectionImpl. java: 2430)

At com. mysql. jdbc. ConnectionImpl. createNewIO (ConnectionImpl. java: 2215)

At com. mysql. jdbc. ConnectionImpl. <init> (ConnectionImpl. java: 813)

At com. mysql. jdbc. JDBC4Connection. <init> (JDBC4Connection. java: 47)

At sun. reflect. GeneratedConstructorAccessor43.newInstance (Unknown Source)

At sun. reflect. delegatingconstruct%cessorimpl. newInstance (delegatingconstruct%cessorimpl. java: 45)

At java. lang. reflect. Constructor. newInstance (Constructor. java: 526)

At com. mysql. jdbc. Util. handleNewInstance (Util. java: 411)

At com. mysql. jdbc. ConnectionImpl. getInstance (ConnectionImpl. java: 399)

At com. mysql. jdbc. NonRegisteringDriver. connect (NonRegisteringDriver. java: 334)

At org. apache. commons. dbcp. DriverConnectionFactory. createConnection (DriverConnectionFactory. java: 38)

At org. apache. commons. dbcp. PoolableConnectionFactory. makeObject (PoolableConnectionFactory. java: 582)

At org. apache. commons. pool. impl. GenericObjectPool. borrowObject (GenericObjectPool. java: 1148)

At org. apache. commons. dbcp. PoolingDataSource. getConnection (PoolingDataSource. java: 106)

At org. apache. commons. dbcp. BasicDataSource. getConnection (BasicDataSource. java: 1044)

At org. springframework. orm. hibernate3.LocalDataSourceConnectionProvider. getConnection (LocalDataSourceConnectionProvider. java: 81)

At org. hibernate. jdbc. ConnectionManager. openConnection (ConnectionManager. java: 446)

... 16 more Caused by: java.net. SocketException: too many open files

At java.net. Socket. createImpl (Socket. java: 447)

At java.net. Socket. <init> (Socket. java: 421)

At java.net. Socket. <init> (Socket. java: 241)

At com. mysql. jdbc. StandardSocketFactory. connect (StandardSocketFactory. java: 257)

At com. mysql. jdbc. MysqlIO. <init> (MysqlIO. java: 300)

... 34 more

========================================================== ======================================

After seeing the error message, I always thought that the connection was not closed after hibernate in the code was established, until the connection was idle for 8 hours and mysql was disconnected, later, a colleague has encountered such a problem before, but has never noticed an exception below: "more Caused by: java.net. socketException: Too Many opened files ", because my program is deployed on linux, because linux has a ulimit maximum number of opened files, the default value is 1024 (ulimit-a to view the relevant information). Later, it was found that there was an InputStream in the jar package encapsulated by others. Only the newly opened and opened files were not closed, and the open files were continuously created in a loop, when an error is reported when the value exceeds 1024 is enabled, add inputstream and disable it!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.