I think that my application is cursed, debug goes where it wants and I don't know why. Line by line debugging seems to analyze also the commented rows. I think that the problems are on my Connection method, I see a significant performance slowdown, and at the third (or fourth nvm) connection I get this error:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
I'm sure that I close the connection each time I've access to the DB (with finally statement out of the try catch in the implementation).
Here's my connection class:
package Connection;
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.rmi.RemoteException; import java.sql.*; import java.util.Properties;
public class ConnectionDB {
public static ResultSet rs = null;
public static Statement stat = null;
public static Connection cn = null;
public static void connect() throws RemoteException {
String dbHost="",dbUser="",dbPassword="";
Properties prop=new Properties();
try
{
//carico il file:
prop.load(new FileInputStream("***/config.properties"));
//Leggo le proprietà del file:
dbHost=prop.getProperty("host");
dbUser=prop.getProperty("user");
dbPassword=prop.getProperty("password");
}catch(FileNotFoundException fe){
System.out.println("config file not found");
}catch(IOException ex){
System.out.println("Error reading config file");
}
try
{
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
dbHost = "jdbc:mysql://"+dbHost;
cn = DriverManager.getConnection(dbHost,dbUser,dbPassword);
stat = cn.createStatement();
}catch(SQLException e){
System.out.println("Can't connect to the DB");
}
catch(ClassNotFoundException cln){
System.out.println("Error using JDBC driver");
}
}
public static void disconnect() throws RemoteException {
try{
if(rs != null) rs.close();
if(stat != null) stat.close();
if(cn != null) cn.close();
}
catch(SQLException sqlEx){
System.out.println("Error: disconnect");
}
}
}