Not able to update db table from one server to another server in JAVA

140 views Asked by At

i am writing a program which can update one DB table on another server . Assume like my program is on server 192.168.195.103 and from here i am trying to connect to DB server IP 54.246.193.86 and port no 1521. So here i am getting struck , please help me folks on this. But i am getting error at line 13 marked below as

Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap
ter could not establish the connection
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:189)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:231)
        at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:345)
        at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:428)
        at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.ja
va:515)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:345)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at Conn.main(Conn.java:13)




import java.sql.*;
import java.io.*;
class Conn {
  public static void main (String[] args) throws Exception
  {
System.out.println("hid");
  // Class.forName ("oracle.jdbc.driver.OracleDriver");


DriverManager.registerDriver( new oracle.jdbc.driver.OracleDriver());

System.out.println("hidd222");      
 **LINE13** --->>Connection conn = DriverManager.getConnection
   ("jdbc:oracle:thin:@54.246.193.86:1521:ROW0", "azglobal_users_prd", "catcat1");
                        // @//machineName:port/SID,   userid,  password

 //Connection conn = DriverManager.getConnection
   // ("jdbc:oracle:thin:@//54.246.193.86:1521/ROW0", "azglobal_users_prd", "catcat1");

System.out.println("hidd");   
try {
     Statement stmt = conn.createStatement();
     try {
    String s="France";
   String d="update ogl_table_status set status = 1 where mc_name='"+ s +"'";
System.out.println(d);
       //ResultSet rset = stmt.executeUpdate(d);
  stmt.executeUpdate(d);
       try {
         //while (rset.next())
          // System.out.println (rset.getString(1));   // Print col 1
       } 
       finally {
         // try { rset.close(); } catch (Exception ignore) {}
       }
     } 
     finally {
       try { stmt.close(); } catch (Exception ignore) {}
     }
   } 
   finally {
     try { conn.close(); } catch (Exception ignore) {}
   }
  }
}
1

There are 1 answers

1
Crollster On

You have probably not configured the AWS security groups for your DB server to accept connections either on port 1521, or from your IP address.

Simply select "Security Groups" from the left hand menu from either EC2, or RDS (depending on how you started your DB), locate your security group and update accordingly.