• Register
0 votes
51 views

Problem :

I am very new to JDBC. Now I am trying to connect to the Oracle 11g database using my ojdbc14 jar on the eclipse kepler IDE with the java 8 on my windows 7 PC. But when I try to run the below code I often face the following error.

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

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

And the encountered Error is as below :

java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

8 4 2
2,300 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I was going through your code which you have posted in your question after going through your jdbc url, I have found the cause behind your error.

localhost:1200/xe should be changed to localhost:1200:xe if xe is your SID for the database.

So please change below code from

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

To the following code.

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

This will fix all the errors.

5 2 1
4,980 points

Related questions

1 vote
1 answer 7 views
7 views
Problem: I need a help , How I can fix this : java.sql.sqlexception: the network adapter could not establish the connection
asked Mar 25 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 9 views
9 views
Problem: Can someone please help fix this uncaught error : java.sql.sqlrecoverableexception: io error: the network adapter could not establish the connection
asked Mar 25 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 3 views
3 views
Problem: I can connect to schema in derp-db.derp.edu, but not herp-devDV.derp.edu. It gives me this message: The network adapter could not establish the connection SQL developer Anyway assistance would be greatly appreciated. Thanks
asked Mar 20 ummesalma 29.2k points
1 vote
1 answer 4 views
4 views
Problem: I am new to oracle and trying to run a simple code with Java but getting an error: The network adapter could not establish the connection jdbc.
asked 5 days ago PkGuy 23.5k points
0 votes
1 answer 6 views
6 views
Problem: I wrote a servlet program and I want it to connect to my Oracle database but it's giving me an error: The network adapter could not establish the connection - Oracle 11g
asked Apr 24 ummeshani 9.5k points
0 votes
1 answer 6 views
6 views
Problem: Please help me: error de e/s the network adapter could not establish the connection
asked Apr 7 rakib1 51.5k points
0 votes
1 answer 15 views
15 views
Problem: factorio couldn't establish network communication with server.
asked Apr 6 niyatiry 3.9k points
1 vote
1 answer 5 views
5 views
Problem: I am trying to develp a JAVA EE application but need to know the solution. Java.sql.sqlexception: no suitable driver found for jdbc:oracle:thin:@localhost:1521:xe.
asked Apr 24 PkGuy 23.5k points
0 votes
1 answer 6 views
6 views
Problem: I made some Java 1.6-Oracle11g-JDBC (using OJDBC 6). I am getting an exception - java.sql.SQLException: Missing IN or OUT parameter at index:: 1 Why is this happening and how do I fix it ?
asked Apr 21 sumaiya simi 43.9k points