3

getting IOException while connecting to oracle 10g database:-

Exception in thread "main" java.sql.SQLException: Io exception: Got minus one from a read call

at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:190)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:363)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:401)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:839)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.myapp.struts.DBConnection.getDBConnection(DBConnection.java:21)
at com.myapp.struts.DBConnection.main(DBConnection.java:31)

Java Result: 1

my class code is following:-

package com.myapp.struts;

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

public class DBConnection {
    Connection connection = null;
    public Connection getDBConnection()throws Exception{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("OUTPUUT     ********driver registered");
    connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system");
    System.out.println("OUTPUUT     ********connection established");
    return connection;

    }
    public static void main(String args[])throws Exception{
        DBConnection db = new DBConnection();
        ResultSet result = null;
        String query = "SELECT * FROM admin;";
        Connection con = null;
        con = db.getDBConnection();
        System.out.println("OUTPUUT     ********111111111");
        Statement st =con.createStatement();
        result = (ResultSet) st.executeQuery(query);
        while(result.next()){
            System.out.println("OUTPUUT     ********");
            System.out.println(result.getInt(1));
            System.out.println(result.getString(2));
            System.out.println(result.getString(3));
            System.out.println(result.getString(4));
        }
        con.close();


    } 
}

AND one more thing i am using netbeans ide and developing a struts project. Struggling with this problem from last two days but yet to get the solution.

Please help????

Senthil
  • 1,244
  • 10
  • 25
Mahendra
  • 301
  • 2
  • 3
  • 10

6 Answers6

2

if Facing problem to connect with Oracle 10g using JDBC, try below things: 1. turn off your machines's Wi-fi. 2. Stop Oracle Service. 3. Start Oracle Service. Now try to connect with DataBase using JDBC. Problem will be resolved now.

Mahendra
  • 301
  • 2
  • 3
  • 10
1

Try removing semicolon at the end of the query

String query = "SELECT * FROM admin";
L10
  • 389
  • 1
  • 11
  • removed but still same problem. by the way this thing will come next after connection establishment. – Mahendra Jul 06 '13 at 16:02
  • I got the problem solved just by replacing the connection url as: connection = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/XE","system","sy‌​stem"); thanks to everyone for your support. – Mahendra Jul 08 '13 at 08:29
1

I got the problem solved just by replacing the connection url as: connection = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/XE","system","sy‌​stem"); thanks to everyone for your support.

Mahendra
  • 301
  • 2
  • 3
  • 10
  • Interesting, why is your localhost not pointing to 127.0.0.1? – SSaikia_JtheRocker Jul 08 '13 at 08:37
  • @JtheRocker:-I got the actual problem today. Problem is, when my machine is connected with some WI-FI and internet connection is up, this problem arises but it works fine if i disconnects the WI-Fi connection. I think oracle service, jdbc and WI-Fi have some conflict while running parallel. – Mahendra Jul 13 '13 at 18:45
  • @JtheRocker:- and one more thing after disabling wifi, restart of oracle service is necessary. – Mahendra Jul 13 '13 at 18:47
  • I haven't encountered a problem such a this - but you can try ping locahost to see which IP address it points when connected to Wi-Fi and when you are disconnected. – SSaikia_JtheRocker Jul 15 '13 at 06:51
0

Try this url instead

"jdbc:oracle:thin:@//localhost:1521/XE" 

or, "jdbc:oracle:thin:@//localhost:1521/xe"

You might also want to try this to track down your problem -

  1. Remove the following while section temporarily

       while(result.next()){
            System.out.println("OUTPUUT     ********");
            System.out.println(result.getInt(1));
            System.out.println(result.getString(2));
            System.out.println(result.getString(3));
            System.out.println(result.getString(4));
        }
    
  2. add this in place of the while loop - result.first();
  3. add this too after that - System.out.println(result.getString(1));
  4. Check if you have any exception now
  5. If you don't get exception, I think, you are having issues with one or more or more of the result.getXXX() functions inside the while loop.

Is a kind of trial and error answer.

Hope this helps.

SSaikia_JtheRocker
  • 5,053
  • 1
  • 22
  • 41
  • :- Thanks for the suggestion. but my problem is not that. – Mahendra Jul 07 '13 at 06:27
  • problem is here in below statement : – Mahendra Jul 07 '13 at 06:27
  • connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","system"); System.out.println("OUTPUUT ********connection established"); – Mahendra Jul 07 '13 at 06:28
  • and infact problem is not with this statement also but with configration of oracle10g and i am not aware of that. – Mahendra Jul 07 '13 at 06:29
  • I though your connection was successful, when you said you could see the OUTPUUT ********connection established message. Maybe if you post the version, database name, table structure and oracle configurations clearly, somebody might help you out here :) – SSaikia_JtheRocker Jul 07 '13 at 09:37
  • No OUTPUUT ********connection established is not getting printed only driver is getting registered. – Mahendra Jul 08 '13 at 06:22
  • I got the problem solved just by replacing the connection url as: connection = DriverManager.getConnection("jdbc:oracle:thin:@//127.0.0.1:1521/XE","system","system"); thanks to everyone for your support. – Mahendra Jul 08 '13 at 08:27
0

IF the database shutdown command is executed then it will not allow anymore new connections and this error will come.

user2369634
  • 897
  • 3
  • 9
  • 17
0

I was also getting the same problem, I got over of it by replacing 8080 port to 1521 Thank you all you all are doing great job for beginner like me

RKP
  • 49
  • 6