-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Data source rejected establishment of connection?
PostPosted: Tue May 03, 2011 5:31 am 
Newbie

Joined: Tue May 03, 2011 5:07 am
Posts: 2
Location: India
Hi All

I am using MySQL database and hibernate and JSP.using hibernate select database store value and prepared view and display using Ajax.i am polling database every 1 seconds using Java script timer that called a ajax function and return the new updated response every 1 second,i got response for some time after that, it result me an error:
Quote:
DBCExceptionReporter:78 - Data source rejected establishment of connection, message from server: "Too many connections"".

I closed the session (and connection) after using it.Help me to sort-out the above define problem.
ServiceManagerDetails.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.arosys.hibernatedatamanager.ServiceManagerDetails" table="servicemanagerdetails">
    <id column="servicemanagerid" name="servicemanagerID" type="string">
      <generator class="assigned"/>
    </id>
    <property column="servicemode" name="servicemode" type="string"/>
    <property column="servicetype" name="servicetype" type="string"/>
    <property column="servicemanagerstatus" name="servicemanagerstatus" type="string"/>
    <property column="controlqueue" name="controlQueue" type="string"/>
    <property column="controlexchange" name="contolExchange" type="string"/>
    <property column="controlroutingkey" name="controlRoutingkey" type="string"/>
  </class>
</hibernate-mapping>

ServiceManagerDetails.java
Code:

package com.arosys.hibernatedatamanager;

public class ServiceManagerDetails
{
    private String servicemanagerID;
    private String servicemode;
    private String servicetype;
    private String servicemanagerstatus;
    private String controlQueue;
    private String contolExchange;
    private String controlRoutingkey;

    public ServiceManagerDetails()
    {
    }
   
    public ServiceManagerDetails(String servicemanagerID,String servicemode,String servicetype,String servicemanagerstatus,String controlQueue,String contolExchange,String controlRoutingkey)
    {
            this.servicemanagerID=servicemanagerID;
            this.servicemode=servicemode;
            this.servicetype=servicetype;
            this.servicemanagerstatus=servicemanagerstatus;
            this.controlQueue=controlQueue;
            this.contolExchange=contolExchange;
            this.controlRoutingkey=controlRoutingkey;
    }


    public void setservicemanagerID(String servicemanagerID)
    {
        this.servicemanagerID=servicemanagerID;
    }
    public String getservicemanagerID()
    {
        return servicemanagerID;
    }

     public void setservicemode(String servicemode)
    {
        this.servicemode=servicemode;
    }
    public String getservicemode()
    {
        return servicemode;
    }

    public void setservicetype(String servicetype)
    {
        this.servicetype=servicetype;
    }
    public String getservicetype()
    {
        return servicetype;
    }

     public void setservicemanagerstatus(String servicemanagerstatus)
    {
        this.servicemanagerstatus=servicemanagerstatus;
    }
    public String getservicemanagerstatus()
    {
        return servicemanagerstatus;
    }

     public void setcontrolQueue(String controlQueue)
    {
        this.controlQueue=controlQueue;
    }
    public String getcontrolQueue()
    {
        return controlQueue;
    }

     public void setcontolExchange(String contolExchange)
    {
        this.contolExchange=contolExchange;
    }
    public String getcontolExchange()
    {
        return contolExchange;
    }

     public void setcontrolRoutingkey(String controlRoutingkey)
    {
        this.controlRoutingkey=controlRoutingkey;
    }
    public String getcontrolRoutingkey()
    {
        return controlRoutingkey;
    }

}


View.jsp
Code:
<%@page import="com.arosys.hibernatedatamanager.ServiceManagerDetails"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.hibernate.Query"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="org.hibernate.cfg.Configuration"%>
<%@page import="java.net.URL"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>

  <html>
  <head> <Title> Service Monitor</Title>
        <script type="text/javascript" src="resources/js/Ajax.js"></script>
  </head>

  <body >
          <br/><br/><br/><br/>
          <div id="monitordiv">

             <form method="get" action="Action.jsp" name="monitor">
<input id="command" type="text" value="">
<input id="servicemanagerid" type="text" value="">
<table border="1" align="center" >
    <tr>
    <td>Service ManagerID</td>
    <td>Service Mode</td>
    <td>Service Type</td>
    <td>status</td>
    <td>control Queue</td>
    <td>control ExchangeName</td>
    <td>control Routingkey</td>
    <td colspan="3" align="center">Action</td>
    </tr>


<%
try{



        URL systemResource=getServletContext().getResource("resources/hibernate.cfg.xml");
         System.out.println("URL-"+systemResource);
        Configuration cfg=new Configuration();
        cfg.configure(systemResource);
        System.out.println("cfg-"+cfg);
        SessionFactory factory=cfg.buildSessionFactory();
        Session session1=factory.openSession();
         System.out.println("session-"+session1);
        String sql_query= "from  ServiceManagerDetails";
        System.out.print("sql_query-"+sql_query);
        Query query=session1.createQuery(sql_query);
        System.out.println(query);
        for(Iterator it=query.iterate();it.hasNext();)
        {
           ServiceManagerDetails std = (ServiceManagerDetails) it.next();
%>


<tr>
    <td><%=std.getservicemanagerID()%> </td>
    <td><%=std.getservicemode()%></td>
    <td><%=std.getservicetype()%></td>
    <td><%=std.getservicemanagerstatus()%>
    <td><%=std.getcontrolQueue()%>
    <td><%=std.getcontolExchange()%>
    <td><%=std.getcontrolRoutingkey()%>
    </td>

<td><input name="pause" type="Button" value="Pause" onclick="sendQuery('pause','<%=std.getservicemanagerID()%>')"/></td>
<td><input name="resume" type="Button" value="Resume" onclick="sendQuery('resume','<%=std.getservicemanagerID()%>')" /></td>
<td><input name="stop" type="Button" value="Stop" onclick="sendQuery('stop','<%=std.getservicemanagerID()%>')" /></td>
</tr>

<%
    }
%>

<%
   session1.close();
}
catch(Exception e)
{
    e.printStackTrace();
}

%>
      </table>

    </form>
     

          </div>
  </body>
 
</html>



Top
 Profile  
 
 Post subject: Re: Data source rejected establishment of connection?
PostPosted: Tue May 03, 2011 6:29 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
at least give time to hibernate to close session .rather 1 sec use 5 sec .handling session on jsp is not good practice.also increase max connection limit in MySQL

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject: Re: Data source rejected establishment of connection?
PostPosted: Tue May 03, 2011 6:40 am 
Newbie

Joined: Tue May 03, 2011 5:07 am
Posts: 2
Location: India
where should i go to close hibernate session ?

Thanks


Top
 Profile  
 
 Post subject: Re: Data source rejected establishment of connection?
PostPosted: Tue May 03, 2011 6:43 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
go through with DAO design pattern.

http://docs.jboss.org/hibernate/core/3. ... tions.html

_________________
Dharmendra Pandey


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.