I do not like to raise a question that is widely asked on the Internet, but I cannot solve it.
I started the project a while ago, and after a month of testing, I hit the "Too many connections" error. I looked at it and “decided” by increasing max_connections. Then it worked.
Since then, more and more people started using it, and it hit again. When I am the only user on the site, I type “show processlist” and about 50 connections appear that are still open (they say “Sleep” in the command). Now I don’t know enough to talk about why they are open, but in my code I checked three times and close every open connection.
t
public int getSiteIdFromName(String name, String company)throws DataAccessException,java.sql.SQLException{
Connection conn = this.getSession().connection();
Statement smt = conn.createStatement();
ResultSet rs=null;
String query="SELECT id FROM site WHERE name='"+name+"' and company_id='"+company+"'";
rs=smt.executeQuery(query);
rs.next();
int id=rs.getInt("id");
rs.close();
smt.close();
conn.close();
return id;
}
, - , .
- ? , ?