2014-12-30 2 views
-1

내 코드 :수 없습니다

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!"); 
     } 
    } 
} 

오류 메시지 : 데이터베이스 업이있는 경우

-------- 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.<init>(PhysicalConnection.java:414) 
    at oracle.jdbc.driver.T4CConnection.<init>(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) 
+2

따라서 Oracle 데이터베이스를 실행 중이며 1521 포트에서 수신 대기 중이십니까? 그렇지 않은 것 같습니다. –

+0

나머지 스택 추적을 추가 할 수 있습니다. 호스트 localhost에서 포트 1521이 연결되었는지 여부를 확인할 수있는 것이 이상적입니다. – antonycc

답변

0

확인합니다. 데이터베이스가 다운되어 연결할 수없는 것 같습니다.