I have created a simple program in JAVA SE with NETBEANS where I have 3 buttons and every time I press a button I send information to my database, at all times I have the connection open and every time I press the button
//Creo la conexión
static Connection connection = null;
Class.forName("com.mysql.jdbc.Driver");
connection =DriverManager.getConnection( "jdbc:mysql://midominio.org:3306/nombreDB", "usuario", "contraseña");
//Dejo la conexión abierta y cada vez que pulso un botón realizado este método.
private void insertarRegistro(int id_persona, int tipo_acceso){
PreparedStatement pst = null;
try {
String sentencia = "INSERT INTO tabla(id_persona, fecha, hora, tipo_acceso) VALUES (?, CURDATE(), CURTIME(), ?)";
pst = connection .prepareStatement(sentencia);
pst.setInt(1, id_persona);
pst.setInt(2, tipo_acceso);
pst.executeUpdate();
pst.close();
} catch (SQLException ex) {
System.out.println("No se ha podido insertar en la Base de Datos.");
} finally{
try {
pst.close();
} catch (SQLException ex) {
}
}
}
Then I open the Task Manager and I see that my program in the Memory column every time I pulse increases the memory but never goes down, and there comes a time that consumes so much memory that the program stays stuck.
How can I solve that it does not raise the memory or that when the button is stopped the memory returns to more or less to its main value?