我正在编写一个可以更新另一台服务器上的一个数据库表的程序。 假设我的程序在服务器192.168.195.103上,从这里我试图连接到数据库服务器IP 54.246.193.86和端口号1521.所以在这里我很震惊,请帮助我这些人。 但我在下面标记为
的第13行收到错误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) {}
}
}
}
答案 0 :(得分:0)
您可能未将数据库服务器的AWS安全组配置为接受端口1521或IP地址上的连接。
只需从左侧菜单中选择EC2或RDS中的“安全组”(取决于您启动数据库的方式),找到您的安全组并进行相应更新。