• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes

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 {
       } catch (ClassNotFoundException e) {
       Connection connect = null;
       try {
        connect = DriverManager.getConnection(
                "jdbc:oracle:thin:@localhost:1200:orcl", "scott", "tiger");
        // jdbc:oracle:thin:@server:1521:xe
       } catch (SQLException e) {
       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

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

0 votes
1 answer 21 views
I am finding difficulty with following issue, any help appreciated: java.sql.sqlexception: can not issue data manipulation statements with executequery().
asked Jul 25 James Martin 2.2k points
0 votes
2 answers 63 views
Problem : I am getting bellow error while trying to execute JDBC code java.sql.sqlexception: operation not allowed after resultset closed
asked Nov 1, 2019 peterlaw 6.9k points
1 vote
2 answers 67 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