Results 1 to 12 of 12
  1. #1
    Join Date
    Jul 2009
    Posts
    5

    Unanswered: java.sql.SQLException: Io exception: Got minus one from a read call

    Hi Friends,
    I am using Oracle 10g.
    Below is my Java code, using which i am trying to connect to the oracle 10g db.
    Kindly pls help.
    When i run the code, i am getting the Exception saying:

    java.sql.SQLException: Io exception: Got minus one from a read call

    Java Source:

    public class JDBC_Oracle
    {
    public static void main(String[] v) {
    try{
    Class.forName("oracle.jdbc.OracleDriver");

    Connection con=DriverManager.getConnection("jdbcracle:thin:@localhost:8080:student","system","pass word");

    Statement s=con.createStatement();

    ResultSet rs = s.executeQuery("select name from student");

    while (rs.next()){
    System.out.println (rs.getString(1));
    System.out.println (rs.getString(2));
    }
    rs.close(); s.close();
    }
    catch(Exception x) {
    x.printStackTrace();
    }
    }
    }

    -Vikas

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Your query only has a single column (name), but you are retrieving two columns from the result set getString(1) and getString(2).

    Please use [code] tags when posting code, that makes it a lot more readable.

  3. #3
    Join Date
    Jul 2009
    Posts
    5
    even though if i change it to *(select * from student), it shows the same exception.
    if possible, pls try to run.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    How should I be able to run this? I don't have your database.

    Where exactly does the exception happen? Which line?
    Are you sure that the connection URL is correct?
    I have never seen port 8080 used for an Oracle listener.

  5. #5
    Join Date
    Jul 2009
    Posts
    5
    the exception occurs at this line;
    Connection con=DriverManager.getConnection("jdbc: oracle:thin: @localhost:8080:student","system","password");

    The connection url is correct. I checked in other sites also.
    If i change 8080 to 1521, then it says:

    java.sql.SQLException: Listener refused the connection with the following error:

    ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
    The Connection descriptor used by the client was:
    localhost:1521:student

    at
    oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java
    :112)

  6. #6
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    12505, 00000, "TNS:listener does not currently know of SID given in connect descriptor"
    // *Cause:  The listener received a request to establish a connection to a
    // database or other service. The connect descriptor received by the listener
    // specified a SID for an instance (usually a database instance) that either
    // has not yet dynamically registered with the listener or has not been
    // statically configured for the listener. This may be a temporary condition
    // such as after the listener has started, but before the database instance
    // has registered with the listener.
    // *Action: 
    //  - Wait a moment and try to connect a second time.
    //  - Check which instances are currently known by the listener by executing:
    //    lsnrctl services <listener name>
    //  - Check that the SID parameter in the connect descriptor specifies
    //    an instance known by the listener.
    //  - Check for an event in the listener.log file.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  7. #7
    Join Date
    Jul 2009
    Posts
    5
    I have attached my *listener.log* file. pls have a look at it and kindly let me know. As i don't have much idea on listener log files.
    kindly help.
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Post Operating System (OS) name & version for DB server system.
    Post results of SELECT * from v$version.

    post results from following OS commands using CUT & PASTE

    lsnrctl status
    lsnrctl service

    >Connection con=DriverManager.getConnection("jdbc: oracle:thin: @localhost:8080:student","system","password");

    try below instead

    Connection con=DriverManager.getConnection("jdbcracle:thin: @localhost:1521:xe","system","password");

    Use valid username & password in line above
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  9. #9
    Join Date
    Jul 2009
    Posts
    5
    Hey, Its working.
    Thank you so much dear friend... long live anacedent...
    I just changed the connection statement as specified by you with valid username and password.
    Thank you.

    will get in touch, if i face any other issues.

    -Vikas

  10. #10
    Join Date
    Dec 2011
    Posts
    1

    java.sql.SQLException: Listener refused the connection with the following error: ORA-

    I too having the same error
    I am attaching my litener file
    My o.s is windows xp,32 bit
    Attached Files Attached Files

  11. #11
    Join Date
    Jan 2012
    Posts
    1

    ResultSet not executing prperly

    I am also having the same problem. I can see that the driver is getting registered. But the program is not able to connect to dbase . Hhere i am enclosing my code . Plz help.

    Here is my prog


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

    public class OracleConnect
    {
    public static void main(String[] args)
    {
    try{
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("your installation of JDBC Driver OK.");
    Connection conn = DriverManager.getConnection(
    "jdbcracle:thin:@127.0.0.1:1521:XE", "user", "user");

    Statement stmt = conn.createStatement();
    ResultSet rset = stmt.executeQuery("select * from login");
    if (rset.next())
    {
    System.out.println(rset.getString(1));
    System.out.println(rset.getString(2));
    }

    stmt.close();
    }
    catch(Exception e)
    { e.printStackTrace();}
    }
    }


    Plz help !!
    Attached Thumbnails Attached Thumbnails error.bmp  
    Attached Files Attached Files

  12. #12
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Code:
    bcm@bcm-laptop:~$ cat Conn.java
    import java.sql.*;
    class Conn {
      public static void main (String[] args) throws Exception
      {
       Class.forName ("oracle.jdbc.OracleDriver");
    
       Connection conn = DriverManager.getConnection
         ("jdbc:oracle:thin:@//localhost:1521/v112", "scott", "tiger");
                            // @//machineName:port/SID,   userid,  password
       try {
         Statement stmt = conn.createStatement();
         try {
           ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
           try {
             while (rset.next())
               System.out.println (rset.getString(1));   // Print col 1
           } 
           finally {
              try { rset.close(); } catch (Exception ignore) {}
           }
         } 
         finally {
           try { stmt.close(); } catch (Exception ignore) {}
         }
       } 
       finally {
         try { conn.close(); } catch (Exception ignore) {}
       }
      }
    }
    bcm@bcm-laptop:~$ javac Conn.java
    bcm@bcm-laptop:~$ export CLASSPATH=/u01/app/oracle/product/11.2.0/dbhome_1/owb/wf/lib/ojdbc14.jar:.
    bcm@bcm-laptop:~$ java Conn
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE	11.2.0.1.0	Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    bcm@bcm-laptop:~$
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •