You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by prakash shanmugam <pr...@gmail.com> on 2006/08/11 08:39:39 UTC

how to over come toomanyconnection error when communicatingMYSQL

hai all,
i have one major issue in my project..
My project is developed using jsp,servlets in Tomcat5 with MySql as
database.. i am using type1 driver
My project is now used by end users in intranet..
When multiple users are accessing at the same time ,its throwing too many
connections exception at sometimes . And at sometimes its dispaying error as
"Operation not allowed after ResultSet is closed"
i dont know how to rectify this .. Can anybody help me to overcome this..
Here is my bean file used for establing database connections...
package com.pts.database;
import java.io.*;
import java.sql.*;
import java.net.*;
public class DBCon
{
private static final String DriverClass = "com.mysql.jdbc.Driver";
private static final String CONNECTION_STRING = "jdbc:mysql://";
private static final String PORT = "3306";
private static final String DATABASE = "opts";
private static final String user = "dav";
private static final String pwd="";
private static Connection con = null;
private static Statement stmt = null;
private static Statement stmt2 = null;
private static PreparedStatement pst = null;
private static ResultSet rs = null;
private static int count = 0;
public static void assignCon()
{
String CONNECTION_IP="100.100.100.6";
try{
Class.forName(DriverClass).newInstance();
}
catch(ClassNotFoundException ce){System.out.println(ce);}
catch(InstantiationException ie){}
catch(IllegalAccessException ie1){}

try{
con = DriverManager.getConnection
(CONNECTION_STRING+CONNECTION_IP+":"+PORT+"/"+DATABASE,user,pwd);
stmt = con.createStatement();
stmt2 = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
}catch(SQLException sqle){System.out.println("STMT:"+sqle);}
}
public static ResultSet retrieveFromDB(String sql) throws SQLException
{
return (stmt.executeQuery(sql));
}
public static ResultSet retrieveScrollDB(String sql) throws SQLException
{
return (stmt2.executeQuery(sql));
}
public static int updateDB(String sql) throws SQLException
{
return (stmt.executeUpdate(sql));
}
public static PreparedStatement prepareStmt(String sql) throws SQLException{
pst=con.prepareStatement(sql);
return pst;
}
public static ResultSet getProjectsList() throws SQLException{
rs=((PreparedStatement)con.prepareStatement("select projID,projName from
proj_det where delFlag=0 || delFlag IS NULL")).executeQuery();
return rs;
}
public Connection getConn() {
return con;
}
public Statement getStmt()
{
return stmt;
}
public static void CloseAll() throws SQLException
{
stmt.close();
stmt2.close();
con.close();
}
}

Hope Any of u can help me.. it would be very much helpful to me if any body
suggest me a solution to this... Because of this issue my project is in
pending..

Thanks in Advance