title: Can't Connect To Remote Oracle Database (11g)
body: <p>I'm trying to connect a linux machine which has oracle database 11gr2 setup inside. There is no problem with connecting PL/SQL developer with any user. Unfortunately, with my simple java application, it's impossible to connect to database.</p>
  
  <p>Here is my java code:</p>
  
  <p><strong>JAVA CODE</strong></p>
  
  <pre><code>package oraConn;
  import java.sql.*;
  public class OraConn {
  
      public static void main(String[] args) {
      Connection connection=null;
      try {
      String driverName= "oracle.jdbc.driver.OracleDriver";
      Class.forName(driverName);
      String serverName="192.168.2.122";
      String portNumber="1521";
      String sid="sas";
      String url="jdbc:oracle:thin:@" + serverName + ":" + portNumber +":"+sid;
      String userName = "system";
      String password = "welcome";    
      connection = DriverManager.getConnection(url,userName,password);
      } catch (Exception e) {
      e.printStackTrace();
  
      }
  }
  }
  </code></pre>
  
  <p>When i run this codeblock, i get an exception like this:</p>
  
  <pre><code>java.sql.SQLException: IO Error: Connection refused 
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
      at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:553)
      at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:254)
      at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at java.sql.DriverManager.getConnection(Unknown Source)
      at oraConn.OraConn.main(OraConn.java:16)
  Caused by: oracle.net.ns.NetException: Connection refused 
      at oracle.net.ns.NSProtocol.connect(NSProtocol.java:399)
      at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
      at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
      ... 7 more
  </code></pre>
  
  <p>I am sure that port 1521 is open because i can use PL/SQL developer. What should i do?</p>