我的應用程序使用Hibernate。我正在研究智能交通系統(ITS)。因此,我每10秒鐘就會跟蹤一次公交車的位置(緯度,經度)。我每10秒調用一次ajax方法,向servlet發出請求。我的應用程序正常工作了一段時間後,它顯示誤差,如何解決異常「com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:數據源拒絕建立連接」?
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
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:160)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473)
at
和
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
我沒有得到如何解決它。我搜索了很多資源,發現它是關於在Hibernate配置文件中管理連接池的。
所以這裏是我的Hiberenate配置文件。
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bus_serverdb</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<!-- Names the annotated entity class -->
任何一個可以告訴我什麼是我必須做的,爲什麼變化?
是的,每當我接近會議。 – Raghu 2014-09-01 08:17:12
我的進程列表顯示'*************************** 90. row ******* Id:454 User:根 主機:本地主機:54282 DB:bus_serverdb 命令:睡眠 時間:28 國家: 信息:NULL' – Raghu 2014-09-01 08:25:36