title: Data source rejected establishment of connection, message from server: "Too many connections"
body: <p>I am using hibenate and spring and getting below exception ween we hit from jmeter with 250 users</p>
  
  <blockquote>
    <p>"Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection,  message from server: "Too many connections"</p>
  </blockquote>
  
  <p>hibernate_cfg.xml</p>
  
  <pre><code>&lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/property&gt;
      &lt;property name="hibernate.connection.url"&gt;jdbc:mysql://localhost:3306/my_db&lt;/property&gt;
      &lt;property name="hibernate.connection.username"&gt;user1&lt;/property&gt;
      &lt;property name="hibernate.connection.pool_size"&gt;1&lt;/property&gt;
      &lt;property name="hibernate.c3p0.min_size"&gt;5&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_size"&gt;50&lt;/property&gt;
      &lt;property name="hibernate.c3p0.timeout"&gt;300&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_statements"&gt;500&lt;/property&gt;
      &lt;property name="hibernate.c3p0.idle_test_period"&gt;3000&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="hibernate.hbm2ddl.auto"&gt;update&lt;/property&gt;`
  </code></pre>
  
  <p>Spring </p>
  
  <pre><code>&lt;bean id="dataSource" scope="prototype" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; 
      &lt;property name="driverClassName"&gt;
          &lt;value&gt;${dbDriver}&lt;/value&gt;
      &lt;/property&gt;  
      &lt;property name="url"&gt;
          &lt;value&gt;${dbURL}&lt;/value&gt; 
      &lt;/property&gt;
      &lt;property name="username"&gt;
          &lt;value&gt;${dbUsername}&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="password"&gt;
          &lt;value&gt;${dbPassword}&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>