title: Unable to connect to Oracle 10g XE
body: <p>My code :</p>
  
  <pre><code>package java_connect;
  
  import java.sql.*;
  
  public class JdbcOracleXe {
  
      public static void main(String[] args) {
          System.out.println("-------- Oracle JDBC Connection Testing ------");
  
          try {
              Class.forName("oracle.jdbc.driver.OracleDriver");
          } catch (ClassNotFoundException e) {
              System.out.println("Where is your Oracle JDBC Driver?");
              e.printStackTrace();
              return;
          }
  
          System.out.println("Oracle JDBC Driver Registered!");
  
          Connection connection = null;
  
          try {
              connection = DriverManager.getConnection(
                  "jdbc:oracle:thin:@localhost:1521/xe", "username",
                  "password");
          } catch (SQLException e) {
              System.out.println("Connection Failed! Check output console");
              e.printStackTrace();
              return;
          }
  
          if (connection != null) {
              System.out.println("You made it, take control your database now!");
          } else {
              System.out.println("Failed to make connection!");
          }
      }
  }
  </code></pre>
  
  <p>Error message :</p>
  
  <pre><code>-------- Oracle JDBC Connection Testing ------
  Oracle JDBC Driver Registered!
  Connection Failed! Check output console
  java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:414)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
      at java.sql.DriverManager.getConnection(DriverManager.java:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:247)
      at java_connect.JdbcOracleXe.main(JdbcOracleXe.java:28)
  </code></pre>