I'm working on a java web project and I have a connection class with the PostgreSQL database, which links to the database called BASE_X that performed properly, but I made a copy of the project that has this class and made another database in PostgreSQL identical to the previous one, just changing the name to BASE_X1 . I wanted to do some new experiments with the new bank that was not populated like the old one, I changed the database name in the link class path URL to go to the new unpopulated bank and compiled the entire project along with the class . I cleared the browser history, cleared the cache, unzipped the project, and then rode the new project with the new path and it connected with the old !! To get the doubt I took the class that was compiled and decompiled to check if there was any error but nothing he was indicating the connection to the new bank !! I have never seen something like that !! And I've done this experiment other times with other non-web projects and they worked. I do not know what's going on ..
Part of the code for the connection class of the first project:
private Connection con;
private final Properties prop = null;
private final String URL = "jdbc:postgresql://localhost:5433/BASE_X";
Part I changed from connection class of second project:
private final String URL = "jdbc:postgresql://localhost:5433/BASE_X1";
Connection code:
package br.com.banco.basex.Connection;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import br.com.banco.basex.Excecoes.FonteDeDadosException;
import java.util.Properties;
public class Conexao implements ConexaoIF {
private Connection con;
private final Properties prop = null;
private final String URL = "jdbc:postgresql://localhost:5433/BASE_X";
public Conexao() throws SQLException {
try {
Class.forName("org.postgresql.Driver");
this.con = DriverManager.getConnection(URL, "postgres", "doremifa");
} catch (FonteDeDadosException | ClassNotFoundException e) {
throw new FonteDeDadosException(
"Não foi possível conectar com o banco de dados!");
}
}
public Connection getConnection() {
return this.con;
}
public void closeAll(PreparedStatement stat) throws FonteDeDadosException {
try {
this.con.close();
stat.close();
} catch (SQLException e) {
throw new FonteDeDadosException("Falha ao fechar conexões");
}
}
public void closeAll(Statement stat) throws FonteDeDadosException {
try {
this.con.close();
stat.close();
} catch (SQLException e) {
throw new FonteDeDadosException("Falha ao fechar conexões");
}
}
}