简体   繁体   中英

getting IOException “got minus one from a read call” while connecting to oracle 10g database

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????

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.

尝试在查询结束时删除分号

String query = "SELECT * FROM admin";

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.

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.

如果执行数据库关闭命令,则它将不再允许新连接,并且将出现此错误。

我也遇到了同样的问题,我通过将8080端口替换为1521来解决它问题谢谢大家对我这样的初学者都做得很好

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM