You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Veselin Kovacevic <ve...@promonte.com> on 2003/11/11 10:56:56 UTC

Problem with ConnectionPool on Linux

Hi,

I have o problem with Tomcat 4.1.24 on SuseLinux7.3. Our application has
Controller servlet (below) where using connection objects from
connection pool. When tomcat started, application working fine and
everything OK that day. But next day when we try to start application we
get error message in isUser method (PortalUserDB class). It's first
place where we use connection object in application. Method isUser is
very simple method for authenticate user (below).
We get this exception: 
SQL Exception:java.sql.SQLException: No operations allowed after
connection closed

Connection object is not null in this case, and this message for me is
not correct.
Next, if I restart tomcat, everything working ok... (for next day).

On windows (we using windows for development platform) we have not this
problem.

What is problem? 
Is configuration server.xml or similar configuration files on Linux
different rather on windows?

Note:
On both platform we using Tomcat 4.1.24 and j2sdk1.4.1_03.


public class Controller extends HttpServlet {	

	private DataSource ds;
	
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		try {
			InitialContext initCtx = new InitialContext();
			Context envCtx =
(Context)initCtx.lookup("java:comp/env"); 
			ds =
(DataSource)envCtx.lookup("jdbc/MySQLPool");
		} catch (Exception e){
			throw new UnavailableException(e.getMessage());
		}
	}
	
	public void doGet(HttpServletRequest request,
HttpServletResponse response)
					  throws IOException,
ServletException {
		
		request.setCharacterEncoding("iso-8859-2");
		
		........................
		........................

		if (ds != null) {
		Connection conn = ds.getConnection();
			if (conn != null) {
				boolean isUserExists =
PortalUserDB.isUser(conn, userName, userPass);
					........................
					........................	
				conn.close();
			}
		........................
		........................

	}
}

public static boolean isUser(Connection conn, String userName, String
userPass)
	throws SQLException, IOException {

	String query = "SELECT user_name FROM admin_user " +
				   "WHERE user_name = ? " +
				   		"AND user_pass = ?";
				   		
	boolean isUserExists = false;
		
	try {
		PreparedStatement pstmt = conn.prepareStatement(query);
		pstmt.setString(1, userName);
		pstmt.setString(2, userPass);
		
		ResultSet rs = pstmt.executeQuery();
	
		isUserExists = rs.next();
	
		rs.close();
		rs = null;
		pstmt.close();
		pstmt = null;
		
	} catch (SQLException sqle) {
		PortalLog.addLogLine("Class: PortalUserDB, Method:
isUser. SQL Exception:" + sqle, userName);
	}
	
	return isUserExists;
}

Thanks,
Veso

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem with ConnectionPool on Linux

Posted by Jon Wingfield <jo...@mkodo.com>.
MySql times out idle connections. If your pool implementation doesn't 
take care of weeding out dead connections you need to add 
autoReconnect=true to your connection string.

HTH,

Jon

Veselin Kovacevic wrote:

> Hi,
> 
> I have o problem with Tomcat 4.1.24 on SuseLinux7.3. Our application has
> Controller servlet (below) where using connection objects from
> connection pool. When tomcat started, application working fine and
> everything OK that day. But next day when we try to start application we
> get error message in isUser method (PortalUserDB class). It's first
> place where we use connection object in application. Method isUser is
> very simple method for authenticate user (below).
> We get this exception: 
> SQL Exception:java.sql.SQLException: No operations allowed after
> connection closed
> 
> Connection object is not null in this case, and this message for me is
> not correct.
> Next, if I restart tomcat, everything working ok... (for next day).
> 
> On windows (we using windows for development platform) we have not this
> problem.
> 
> What is problem? 
> Is configuration server.xml or similar configuration files on Linux
> different rather on windows?
> 
> Note:
> On both platform we using Tomcat 4.1.24 and j2sdk1.4.1_03.
> 
> 
> public class Controller extends HttpServlet {	
> 
> 	private DataSource ds;
> 	
> 	public void init(ServletConfig config) throws ServletException {
> 		super.init(config);
> 		try {
> 			InitialContext initCtx = new InitialContext();
> 			Context envCtx =
> (Context)initCtx.lookup("java:comp/env"); 
> 			ds =
> (DataSource)envCtx.lookup("jdbc/MySQLPool");
> 		} catch (Exception e){
> 			throw new UnavailableException(e.getMessage());
> 		}
> 	}
> 	
> 	public void doGet(HttpServletRequest request,
> HttpServletResponse response)
> 					  throws IOException,
> ServletException {
> 		
> 		request.setCharacterEncoding("iso-8859-2");
> 		
> 		........................
> 		........................
> 
> 		if (ds != null) {
> 		Connection conn = ds.getConnection();
> 			if (conn != null) {
> 				boolean isUserExists =
> PortalUserDB.isUser(conn, userName, userPass);
> 					........................
> 					........................	
> 				conn.close();
> 			}
> 		........................
> 		........................
> 
> 	}
> }
> 
> public static boolean isUser(Connection conn, String userName, String
> userPass)
> 	throws SQLException, IOException {
> 
> 	String query = "SELECT user_name FROM admin_user " +
> 				   "WHERE user_name = ? " +
> 				   		"AND user_pass = ?";
> 				   		
> 	boolean isUserExists = false;
> 		
> 	try {
> 		PreparedStatement pstmt = conn.prepareStatement(query);
> 		pstmt.setString(1, userName);
> 		pstmt.setString(2, userPass);
> 		
> 		ResultSet rs = pstmt.executeQuery();
> 	
> 		isUserExists = rs.next();
> 	
> 		rs.close();
> 		rs = null;
> 		pstmt.close();
> 		pstmt = null;
> 		
> 	} catch (SQLException sqle) {
> 		PortalLog.addLogLine("Class: PortalUserDB, Method:
> isUser. SQL Exception:" + sqle, userName);
> 	}
> 	
> 	return isUserExists;
> }
> 
> Thanks,
> Veso
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem with ConnectionPool on Linux

Posted by Steph Richardson <st...@kvasar.com>.
My guess is you have some kind of job that runs at night that kicks or restarts your dB server ??
See if restarting your MySQL server in the middle of the day produces the same results.
Anyway to make DBCP tolerant of the database dissapearing, try adding autoReconnect=true to your jdbc url. As in :

jdbc:mysql://127.0.0.1:3306/mydb?autoReconnect=true





> -----Original Message-----
> From: Veselin Kovacevic [mailto:veso@promonte.com]
> Sent: Tuesday, November 11, 2003 4:57 AM
> To: tomcat-user@jakarta.apache.org
> Subject: Problem with ConnectionPool on Linux
> 
> 
> Hi,
> 
> I have o problem with Tomcat 4.1.24 on SuseLinux7.3. Our application has
> Controller servlet (below) where using connection objects from
> connection pool. When tomcat started, application working fine and
> everything OK that day. But next day when we try to start application we
> get error message in isUser method (PortalUserDB class). It's first
> place where we use connection object in application. Method isUser is
> very simple method for authenticate user (below).
> We get this exception: 
> SQL Exception:java.sql.SQLException: No operations allowed after
> connection closed
> 
> Connection object is not null in this case, and this message for me is
> not correct.
> Next, if I restart tomcat, everything working ok... (for next day).
> 
> On windows (we using windows for development platform) we have not this
> problem.
> 
> What is problem? 
> Is configuration server.xml or similar configuration files on Linux
> different rather on windows?
> 
> Note:
> On both platform we using Tomcat 4.1.24 and j2sdk1.4.1_03.
> 
> 
> public class Controller extends HttpServlet {	
> 
> 	private DataSource ds;
> 	
> 	public void init(ServletConfig config) throws ServletException {
> 		super.init(config);
> 		try {
> 			InitialContext initCtx = new InitialContext();
> 			Context envCtx =
> (Context)initCtx.lookup("java:comp/env"); 
> 			ds =
> (DataSource)envCtx.lookup("jdbc/MySQLPool");
> 		} catch (Exception e){
> 			throw new UnavailableException(e.getMessage());
> 		}
> 	}
> 	
> 	public void doGet(HttpServletRequest request,
> HttpServletResponse response)
> 					  throws IOException,
> ServletException {
> 		
> 		request.setCharacterEncoding("iso-8859-2");
> 		
> 		........................
> 		........................
> 
> 		if (ds != null) {
> 		Connection conn = ds.getConnection();
> 			if (conn != null) {
> 				boolean isUserExists =
> PortalUserDB.isUser(conn, userName, userPass);
> 					........................
> 					........................	
> 				conn.close();
> 			}
> 		........................
> 		........................
> 
> 	}
> }
> 
> public static boolean isUser(Connection conn, String userName, String
> userPass)
> 	throws SQLException, IOException {
> 
> 	String query = "SELECT user_name FROM admin_user " +
> 				   "WHERE user_name = ? " +
> 				   		"AND user_pass = ?";
> 				   		
> 	boolean isUserExists = false;
> 		
> 	try {
> 		PreparedStatement pstmt = conn.prepareStatement(query);
> 		pstmt.setString(1, userName);
> 		pstmt.setString(2, userPass);
> 		
> 		ResultSet rs = pstmt.executeQuery();
> 	
> 		isUserExists = rs.next();
> 	
> 		rs.close();
> 		rs = null;
> 		pstmt.close();
> 		pstmt = null;
> 		
> 	} catch (SQLException sqle) {
> 		PortalLog.addLogLine("Class: PortalUserDB, Method:
> isUser. SQL Exception:" + sqle, userName);
> 	}
> 	
> 	return isUserExists;
> }
> 
> Thanks,
> Veso
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org