1

I am very new with Oracle, I have installed 11g 64 bit on my Windows 10. And only started the oracle database using emctl start dbconsole. I have the following code to be connected to my database, which results in the shown exception. I have investigated a lot about this issue on web/stackoverflow/youtube etc, and could not find a straightforward working procedure, would you What is the problem? Please note that the exception happens at the following line:

con = DriverManager.getConnection(url, props);

The code looks like:

    String url = "jdbc:oracle:thin:@localhost:1158:searchengine";

    //properties for creating connection to Oracle database
    Properties props = new Properties();
    props.setProperty("user", "sys");
    props.setProperty("password", "1234");

    //creating connection to Oracle database using JDBC
    try
        {
            //Class.forName("oracle.jdbc.OracleDriver");
            con = DriverManager.getConnection(url, props);
            //con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:searchengine", "system", "1234");
            String query = "alter session set nls_calendar='Persian'";
            PreparedStatement pr = con.prepareStatement(query);
            pr.execute();
            query = "select sysdate from dual";
            pr = con.prepareStatement(query);
            ResultSet res = pr.executeQuery();
            while (res.next())
                {
                    System.out.println(res.toString());
                }
        }
    catch (Exception e)
        {
            e.printStackTrace();
            return false;
        }

    java.sql.SQLRecoverableException: IO Error: Got minus one from a read call
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:489)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:553)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:254)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:528)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:208)
    at Controllers.DBController.connect(DBController.java:24)
    at Wrapper.TestMain.start(TestMain.java:21)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: oracle.net.ns.NetException: Got minus one from a read call
    at oracle.net.ns.Packet.receive(Packet.java:311)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:300)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1140)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:340)
  • Are you sure that 1158 is the correct port number (in the url String)? - I'd expect it to be 1521. Also, is the service name correct - "searchengine", rather than "orcl"? – stefan Jun 20 '17 at 18:19
  • The port number has been assigned by the Oracel installer, searchengine is the database name and SID. If you recommend to change those to 1158 and orcl, please let me know how? – Yahya Hassanzadeh Jun 20 '17 at 18:25
  • You have coded: String url = "jdbc:oracle:thin:@localhost:1158:searchengine"; // try and change 1158 in this string to: 1521, and then compile / run (again). – stefan Jun 20 '17 at 18:28
  • Well, that simply does not work, as after the installation the Oracle prompted as localhost:1158/em, hence it is available on 1158 not on 1521. I meant if the change is needed to be committed inside Oracle – Yahya Hassanzadeh Jun 20 '17 at 18:42
  • Okay - leave the port number at 1158, then. Now for the service name: you wrote (in your last comment) "localhost:1158/em". But in your String url you put "jdbc:oracle:thin:@localhost:1158:searchengine". Try and change this to: "jdbc:oracle:thin:@localhost:1158/em". – stefan Jun 20 '17 at 18:47
0

"emctl start dbconsole" is a command to start Enterprise Manager (EM), which is tool comes bundled with Oracle Database, and used for monitoring and managing the Oracle Database.

I believe localhost:1158/em is the URL for Enterprise Manager(EM), so is the port.

The EM and DB port won't be same, in your case the DB port should be 1521 and SID should be ORCL.

So, your connection URL should look like "jdbc:oracle:thin:@localhost:1521:orcl".

Not the answer you're looking for? Browse other questions tagged or ask your own question.