0

when iam runnig the code i will get the error Exception in thread "main" java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection

package com.karunakar.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SelectAll {

    public static void main(String[] args) throws SQLException {
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe"," system","1234") ;
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery( " select*from stu");
        while( rs.next())
        {
            System.out.println(rs.getInt(1)+".."+rs.getString(2));
        }
        con.close();

    }
} 
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Various questions here. First of all, is your database running in the background? Can you share the whole stacktrace in order to get a better look at what's happening? – akortex Jun 21 '21 at 12:59
  • IIRC, the connection URL should be `jdbc:oracle:thin:@//localhost:1521/xe`. – Mark Rotteveel Jun 21 '21 at 13:15

0 Answers0