Connection problems with Postgresql(ghost URL)

Asked

Viewed 103 times

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");
    }

  }
}
  • 2

    Most likely it’s somewhere else that makes that connection

  • @Jéferson But this piece of code that indicates the way!

  • Post the code on which you make the connection

  • Is a servlert project? vc did not copy and paste the folder and renamed the project?

  • @rray Yes there are Servlets and jsp! ! Maven web project!!

  • 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!!

  • Projects don’t have the same root context name (don’t remember the exact name) ?

  • @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!!!

  • Aaah understood, I thought I had copied the whole project. then n should be what I said.

Show 4 more comments

1 answer

1

I’ve never seen such a strange situation!! Sometimes this type of episode really happens, maybe it is a "byte of the beyond", that Uira mock our high Defense citizens worthy and respected programmers...

I solved the problem like this:

Since the old project was happy , he is not the problem , and then I went to Postgressql and made the only plausible solution:

Fez backup old bank BASE_X and deleted it from Postgresql.
It was shot and fall , as the old no longer existed , he connected with the new bank BASE_X1 unpopulated!!
See you around!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.