0

I am creating a class to connect to my oracle database. But as information I have to access from my bank is: User, password, host, port, and the name of the service, I am trying to connect to the bank and I return the next error:

java.sql.SQLException: Exceção de E/S: The Network Adapter could not establish the connection

Class:

private static final String DEFAULT_URL = "jdbc:oracle:thin:@//rachml-scan.redetendencia.com.br:1521:backofficeint.redetendencia.com.br";
//HOST:rachml-scan.redetendencia.com.br
//Port: 1521
//Service Name: backofficeint.redetendencia.com.br

private static final String DEFAULT_USERNAME = "";
private static final String DEFAULT_PASSWORD = "";

 public Connection getConnection() throws ClassNotFoundException, SQLException
    {
        Connection conn = null;
        try
        {
            Class.forName("oracle.jdbc.OracleDriver");
            conn = DriverManager.getConnection(DEFAULT_URL,DEFAULT_USERNAME,DEFAULT_PASSWORD);
        }
        catch (ClassNotFoundException erroClass) {
            System.out.println("Classe Driver JDBC não foi localizado, erro = "
                    + erroClass);
        }
        catch (SQLException erroSQL) {
            System.out.println("Erro de conexão com o Banco de dados, erro = "
                    + erroSQL);
        }
        return conn;
    }

Does anyone know u solution?

  • Possible duplicate https://stackoverflow.com/questions/12574414/io-error-the-network-adapter-could-not-establish-the-connection – duggu Feb 22 '18 at 12:22
  • Any specific reason why you are trying to do this from your app? Putting the username/password in an app doesn't appear to be a great idea. – Gaurav Singh Faujdar Feb 22 '18 at 12:23
  • 2
    Use a REST API as a middle-man. Connecting directly to a remote database from an Android device is generally **a very bad idea**. [This answer](https://stackoverflow.com/questions/26470117/can-we-connect-remote-mysql-database-in-android-using-jdbc/26471486#26471486) goes into a lot more detail as to why this is such a bad idea. – Michael Dodd Feb 22 '18 at 12:24

0 Answers0