I want to connect my java file to amazon oracle database. 

DataSource.java
===============

```
public class DataSource {

private static String dbName = System.getenv("PUBLIC");
private static String userName = System.getenv("root");
private static String password = System.getenv("3deemala7sas");
private static String hostname = System.getenv("oracleinstance.ctnrs4kazdmm.ap-south-1.rds.amazonaws.com");
private static String port = System.getenv("1521");

public static final String JDBC_DRIVER = "oracle.jdbc.OracleDriver";
public static final String DB_URL = "jdbc:oracle:thin://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password;

public static boolean checkDomain()
{
    if (System.getenv("oracleinstance.ctnrs4kazdmm.ap-south-1.rds.amazonaws.com") != null) {
        return true;
    }
    return false;
}

```

DbConnection.java
=================

```
public static Connection getConnection( )
{

    try {
        Class.forName(DataSource.JDBC_DRIVER);
         connection = DriverManager.getConnection(DataSource.DB_URL);
        //connection = (Connection) DriverManager.getConnection(DataSource.DB_URL);

        System.out.println("Connected ....");

        return connection;
    }
     catch (SQLException ex) {
        System.out.println("Error syntax");
         System.out.println(ex.toString());
         ex.printStackTrace();
    }catch (ClassNotFoundException ex) {
        System.out.println("Class not found error ...");
    }

    return null;
}

```

App01.java
==========

```
public class App01 {

public static void main(String[] args) throws SQLException {
    Connection connection = null ;
    System.out.println(DataSource.checkDomain());
   connection =  DbConnection.getConnection();

}}

```

Exception
=========

java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

Note: I have connected successfully using dbvisualizer, also tried to use neatbeas database services and it is not connecting too 

Netbeans error : Cannot establish a connection to jdbc:oracle:thin:@oracleinstance.ctnrs4kazdmm.ap-south-1.rds.amazonaws.com:1521:XE using oracle.jdbc.OracleDriver (Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
 )