简体   繁体   English

在连接到oracle 10g数据库时,获取IOException“从读取调用中减去一个”

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

getting IOException while connecting to oracle 10g database:- 连接到oracle 10g数据库时获取IOException: -

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 Java结果: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. 还有一件事我正在使用netbeans ide并开发一个struts项目。 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. 如果面临使用JDBC连接Oracle 10g的问题,请尝试以下事项:1。关闭机器的Wi-Fi。 2. Stop Oracle Service. 2.停止Oracle服务。 3. Start Oracle Service. 3.启动Oracle服务。 Now try to connect with DataBase using JDBC. 现在尝试使用JDBC连接DataBase。 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"); 我只是通过将连接URL替换为: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" 或者, "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(); 添加它代替while循环 - result.first();
  3. add this too after that - System.out.println(result.getString(1)); 之后添加它 - 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. 如果你没有得到异常,我想,你在while循环中遇到一个或多个result.getXXX()函数的问题。

Is a kind of trial and error answer. 是一种反复试验的答案。

Hope this helps. 希望这可以帮助。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在与Oracle数据库连接的Java应用程序中发现问题,SQLException:Io异常:从读取调用中减去一个,我该如何解决? - Found issue in java application connecting with oracle database,SQLException: Io exception: Got minus one from a read call ,how I can solve it? 如何解决从 oracle 11g jdbc 7/14 jdk 1.7 中的读取调用中得到减一? - how to resolve Got minus one from a read call in oracle 11g jdbc 7/14 jdk 1.7? 连接到 Amazon RDS Oracle 实例时如何处理“从读取调用中得到减一”错误 - How to approach a "Got minus one from a read call" error when connecting to an Amazon RDS Oracle instance java.sql.SQLException:Io异常:在与oracle 11g进行JDBC连接期间,从读取调用中减去了一个 - java.sql.SQLException: Io exception: Got minus one from a read call during JDBC connection with oracle 11g 从 Oracle 10g 检索 CLOB 时出错 - Error while retieving CLOB from Oracle 10g 在没有JDBC的情况下将Android应用程序与远程Oracle数据库10g或11g连接 - Connecting Android application with Remote oracle database 10g or 11g without JDBC java.sql.SQLException:Io异常:在与oracle的JDBC连接期间从读取调用中减去了一个 - java.sql.SQLException: Io exception: Got minus one from a read call during JDBC connection with oracle 从oracle 10g数据库获取数据时,java中的无效列索引错误。 不能找出问题所在 - invalid column index error in java while fetching data from oracle 10g database. Cant figure out whats wrong 通过Java连接到Oracle 10g Express Edition的问题 - problem in connecting to oracle 10g express edition through java 连接 Oracle 10g Express Edition 和 Java - connecting Oracle 10g Express Edition and Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM