简体   繁体   中英

Not able to connect to Oracle DB getting error as java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

Here is the code which i am trying- ORACLE driver is loaded successfully but getting in get connection that statement-

public class OracelConn {
   public static void main(String[] args) throws Exception {
      try {
         try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
         } catch (ClassNotFoundException e) {
            System.out.println("Please include Classpath  Where your ORACLE Driver is located");
            e.printStackTrace();
            return;
         }
         System.out.println("ORACLE driver is loaded successfully");
         Connectioncon=DriverManager.getConnection( "jdbc:oracle:thin:or0132p.exg.com:1521:OP0132.exg.com", "wsteam", "wsteam");

         Statement stmt = con.createStatement();
         ResultSet rs = stmt.executeQuery("select TC_ORDER_ID from orders where tc_order_id='0296906379'");
         while (rs.next())
            System.out.println(rs.getString("TC_ORDER_ID"));

         con.close();
         } catch (Exception e) {
             System.out.println(e);
         }
      }
   }

There seems to be an issue with your URL format. Below are supported formats:

If you have an SID, use this (older) format:

jdbc:oracle:thin:@[HOST][:PORT]:SID

If you have an Oracle service name, use this (newer) format:

jdbc:oracle:thin:@//[HOST][:PORT]/SERVICE

Source: orafaq

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM