0
I am working on a web java project and have a connection class with the Postgresql database ,which connects the database called BASE_X which performed well, but I made a copy of the project that has this class and made another database in Postgresql identical to the previous database, 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 name of the database in the URL of the connection class path to go to the new unpopulated bank and compiled the whole project along with the class.
I cleaned the browser history, cleaned the cache memory, unemplanted the project, and then ran the new project with the new path and it connected with the old one!!
To remove the doubt I took the class that was compiled and decompiled to check if there was any error but nothing it was indicating the connection to the new bank!! I’ve never seen anything like it!! And I’ve done this experience other times with other non-web projects and it worked. I don’t know what’s going on..
Part of the connection class code of the first project:
private Connection con;
private final Properties prop = null;
private final String URL = "jdbc:postgresql://localhost:5433/BASE_X";
Part that I changed the connection class of the second project:
private final String URL = "jdbc:postgresql://localhost:5433/BASE_X1";
Code that makes the connection:
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");
}
}
}
Most likely it’s somewhere else that makes that connection
– Jéf Bueno
@Jéferson But this piece of code that indicates the way!
– Pena Pintada
Post the code on which you make the connection
– Jéf Bueno
Is a servlert project? vc did not copy and paste the folder and renamed the project?
– rray
@rray Yes there are Servlets and jsp! ! Maven web project!!
– Pena Pintada
This class has no problems!! The problem is that when the project opens in the browser and I fill out the form it forwards the data to the populated database and not to the new one!! I have no idea what is happening! I even uninstalled netbeans!!
– Pena Pintada
Projects don’t have the same root context name (don’t remember the exact name) ?
– rray
@rray How so dude , META-INF.context.xml? It has another name,this part I did not copy, I created a new project and then includes the pages and classes of the old project, sorry it took I did not see your last comment!!!
– Pena Pintada
Aaah understood, I thought I had copied the whole project. then n should be what I said.
– rray