title: How to resolve the Exception “com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection”?
body: <p>my application uses Hibernate. I am working on an ITS(Intelligent Transport System) So here every 10 seconds I have track the position(latitude, longitude) of bus. I call a ajax method every 10 sec which makes request to servlet. My application works fine for some time period, after that it shows error as ,</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I am not getting how to resolve it. I searched many resource and found that it is about managing connection pool in hibernate configuration file.</p>
  
  <p>So here is my Hiberenate configuration file.</p>
  
  <pre><code>&lt;hibernate-configuration&gt;
  &lt;session-factory&gt;
  &lt;!-- Database connection settings --&gt;
  &lt;property name="connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
  &lt;property name="connection.url"&gt;jdbc:mysql://localhost:3306/bus_serverdb&lt;/property&gt;
  &lt;property name="connection.username"&gt;root&lt;/property&gt;
  &lt;property name="connection.password"&gt;root&lt;/property&gt;
  
  &lt;!-- JDBC connection pool (use the built-in) --&gt;
  &lt;property name="connection.pool_size"&gt;1&lt;/property&gt;
  
  &lt;!-- SQL dialect --&gt;
  &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
  &lt;!-- Disable the second-level cache  --&gt;
  &lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;
  
  &lt;!-- Echo all executed SQL to stdout --&gt;
  &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
  &lt;!-- Drop and re-create the database schema on startup --&gt;
  &lt;!-- &lt;property name="hbm2ddl.auto"&gt;create&lt;/property&gt; --&gt;
  
  &lt;!-- Names the annotated entity class --&gt;
  </code></pre>
  
  <p></p>
  
  <p>Can any one tell me what are the changes I have to do and why?</p>