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.xmlCode:
<?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.javaCode:
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.jspCode:
<%@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>