java sql SQLException IO Exception The Network adapter could not establish the connection

0 votes

Hello, I'm trying to establish a connection to an Oracle 11g database using the ojdbc14 jar on Eclipse Kepler with Java 8 on a Windows 7 operating system. However, I encounter the following issue when I run the code. Here is mine and any necessary corrections.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Scanner;

    public class JDBCExample {
      public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("enter your databse details");
       System.out.println("user name");
       String uName = sc.next();
       System.out.println("password");
       String pWord = sc.next();
       try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
       } catch (ClassNotFoundException e) {
        e.printStackTrace();
       }
       Connection conn = null;
       try {
        conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
        // jdbc:oracle:thin:@server:1521:xe
       } catch (SQLException e) {
        e.printStackTrace();
       }
       if (conn != null) {
        System.out.println("Successfully connected to DB");
        } else {
        System.out.println("Failed to connect to DB");
       }
   }
}

And the Errors are as follows.

 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(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at JDBCExample.main(JDBCExample.java:23)

Can someone please help me with this? 

Sep 12, 2022 in Database by Kithuzzz
• 38,010 points
4,688 views

1 answer to this question.

0 votes

As a result of our chat, you can use the command prompt to telnet into a database. After navigating jdbcurl, I discovered the issue.

localhost:1521/xe should be localhost:1521:xe if xe is SID for your database.

Change this code from

conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521/xe", "scott", "tiger");

To

conn = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1521:xe", "scott", "tiger");

I hope this helps you.

answered Sep 13, 2022 by narikkadan
• 63,420 points

Related Questions In Database

0 votes
0 answers

The java.sql.SQLException: Fail to convert to internal representation

I want to do this query: String query ...READ MORE

Aug 20, 2022 in Database by Kithuzzz
• 38,010 points
1,633 views
0 votes
0 answers
0 votes
0 answers

Windows could not start the SQL Server (MSSQLSERVER) on Local Computer... (error code 3417)

I moved the MSSQL11.MSSQLSERVERMSSQL folder from Program ...READ MORE

Aug 28, 2022 in Database by Kithuzzz
• 38,010 points
321 views
+4 votes
11 answers

How to import a jar file in Eclipse?

Click on File > Import. The Import ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,120 points
352,376 views
0 votes
1 answer

Which is the best GUI designer for Eclipse?

Windows Builder Pro is the best GUI ...READ MORE

answered May 21, 2018 in Java by Akrati
• 3,190 points
1,599 views
0 votes
2 answers

When I am running eclispe on my computer it is throwing error. How to resolve it?

If you have downloaded the 64 bit ...READ MORE

answered Dec 10, 2018 in Java by Sushmita
• 6,910 points
774 views
0 votes
1 answer

Eclipse Oxygen fails to start

I think you need to make some ...READ MORE

answered Jun 7, 2018 in Java by code.reaper12
• 3,500 points
977 views
0 votes
1 answer
0 votes
1 answer

Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection. (Microsoft SQL Server, Error: 18452) in sql 2008

Solution Go to Start > Programs > Microsoft SQL Server > Enterprise Manager. Right-click the SQL ...READ MORE

answered Sep 12, 2022 in Database by narikkadan
• 63,420 points
857 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP