我无法通过JDBC中的unix服务器连接到Oracle DB

时间:2017-08-01 08:28:30

标签: java oracle unix jdbc

我写了一个简单的代码来连接到DB

static final String JDBC_DRIVER = "com.oracle.jdbc.OracleDriver";  
static final String DB_URL ="jdbc:oracle:thin:@unix_server_name:1521:ab";

//  Database credentials
static final String USER = "xyz";
static final String PASS = "xyz";

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try{
    //STEP 2: Register JDBC driver
    Class.forName("oracle.jdbc.driver.OracleDriver");

    //STEP 3: Open a connection
    System.out.println("Connecting to database...");
    conn = DriverManager.getConnection(DB_URL,USER,PASS);
    System.out.println("Connection successful");

每当我运行此代码时,我都会收到错误:

  

连接数据库... java.sql.SQLRecoverableException:IO错误:   网络适​​配器无法建立连接   oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:419)at at   oracle.jdbc.driver.PhysicalConnection。(PhysicalConnection.java:536)   在oracle.jdbc.driver.T4CConnection。(T4CConnection.java:228)at   oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)   在oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)at   java.sql.DriverManager.getConnection(未知来源)at   java.sql.DriverManager.getConnection(未知来源)at   PLSQL_JDBC.query_jdbc.main(query_jdbc.java:26)引起:   oracle.net.ns.NetException:网络适配器无法建立   连接

请帮帮我.. 谢谢

0 个答案:

没有答案