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

0 votes
1 answer 3 views
3 views
Problem: Java program to demonstrate this error. This program reproduce this error by first leaving out the required JDBC JAR from classpath and also not explicitly registering the driver before use by not calling Class.forName() method.
asked Feb 18 Ali 4.4k points
0 votes
1 answer 7 views
7 views
Problem: java.sql.sqlexception: ora-28040: no matching authentication protocol.
asked Feb 15 Ethan ross 1.8k points
0 votes
1 answer 7 views
7 views
Problem: I am getting this error message when I start Eclipse Helios on Windows 7: My eclipse.ini looks as follows: -startup plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar -vm P:\Programs\jdk1.6\bin --launcher.library plugins/org.eclipse.equinox.launcher.win32. ... .requiredJavaVersion=1.5 -Xms120m -Xmn100m -Xmx1024m My JAVA_HOME is correctly set as far as I can tell. How can I fix this?
asked Feb 16 Ali 4.4k points
0 votes
1 answer 15 views
15 views
Problem: could not publish to the server. java.lang.indexoutofboundsexception
asked Feb 12 Shovo210 2.7k points
0 votes
1 answer 7 views
7 views
Problem: I have a JSF application that uses Eclipse Persistence Services - 2.1.1.v20100817-r8050, and I sometimes get the following error: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.1.v20100817-r8050): org.eclipse.persistence.exceptions.DatabaseException ... idea what is causing it. The exception is thrown in the following function on the "return q.getResultList();" line.
asked 6 days ago Ali 4.4k points
0 votes
1 answer 7 views
7 views
Problem: ora-28009: connection as sys should be as sysdba or sysoper
asked Feb 18 Ethan ross 1.8k points
0 votes
1 answer 41 views
41 views
Why i am seeing this error can someone give me some explanation "Could not reserve enough space for object heap"” and how to resolve this issue.
asked Sep 14, 2020 Daniel Anderson 4k points
0 votes
1 answer 1.5K views
1.5K views
Problem : When I run the apache tomcat7.0.56 in Eclipse, I get below error Error: Could not find or load main class org.apache.catalina.startup.Bootstrap How can I fix the above problem?
asked Jan 18, 2020 jwilliam 3.9k points
0 votes
1 answer 140 views
140 views
Problem : I am having a box with 8gb of ram, so I don't think the total memory is the issue. This application is running properly on boxes with 6gb or less ram. What I am trying to do is to reserve 3GB of space using -Xmx3G command under "VM ... : Error occurred during initialization of VM; Could not reserve enough space for object heap using -Xmx3G Why am I getting such error any clue?
asked Nov 26, 2019 alecxe 7.5k points