• Register
0 votes
29 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

2.3k points

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.

5k points

Related questions

1 vote
2 answers 131 views
131 views
Problem: Dear all, Right now I’ve imported a maven project into my eclipse IDE and I changed my java path library to work on java 1.7 Suddenly, eclipse started showing an error but I’ve got no errors in my files there. The error is “java compiler level ... Project Problem (Java Version Mismatch) Please tell me how to resolve this error (I want to have my JRE version as 1.7 only).
asked Mar 22 Gavin 15.3k points
0 votes
1 answer 43 views
43 views
Problem : I created a project by Maven integration in Eclipse , but in the work space in all JSP files have bellow message: The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
asked Oct 31, 2019 peterlaw 6.9k points
0 votes
1 answer 1.3K views
1.3K views
Problem : I have already placed the JSTL JAR file in the WEB-INF/lib directory. But still, the JSP can't resolve the taglib. I get the below error: Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
asked Oct 19, 2019 peterlaw 6.9k points