简体   繁体   English

如何解决从 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?

I am using netbeans and jdk 7 updt 9 with 1.7 and following is my code.我在 1.7 中使用 netbeans 和 jdk 7 updt 9,以下是我的代码。

public class jd {
    public static void main(String[] args) throws ClassNotFoundException, SQLException 
{
        
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");
        System.out.println("Connection successful");
       // Statement s = con.createStatement();
       
    }
    
}

output is输出是

 run:
    Exception in thread "main" java.sql.SQLRecoverableException: IO Error: Got minus one from a read call
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:673)
        at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:715)
        at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:385)
        at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:30)
        at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:564)
        at java.sql.DriverManager.getConnection(DriverManager.java:571)
        at java.sql.DriverManager.getConnection(DriverManager.java:215)
        at jd.main(jd.java:22)
    Caused by: oracle.net.ns.NetException: Got minus one from a read call
        at oracle.net.ns.Packet.receive(Packet.java:314)
        at oracle.net.ns.NSProtocolStream.negotiateConnection(NSProtocolStream.java:153)
        at oracle.net.ns.NSProtocol.connect(NSProtocol.java:263)
        at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1360)
        at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:486)
        ... 7 more

Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

DriverManager throws this error when it tries to get a connection with invalid URL. DriverManager 在尝试使用无效 URL 获取连接时会引发此错误。 Make sure your URL is valid.确保您的 URL 有效。 Things to checkout:结账事项:

  1. Port: Oracle db runs on 1521. (note: don't confuse yourself with webport of oracle, which can be any other port as in your URL 1158).端口:Oracle db 在 1521 上运行。(注意:不要将自己与 oracle 的 webport 混淆,它可以是您的 URL 1158 中的任何其他端口)。
  2. DB name: Get the db name from Oracle Web UI: (home->adminIstration->aboutdatabase->settings)数据库名称:从 Oracle Web UI 获取数据库名称:(home->adminIsration->aboutdatabase->settings)
  3. URL format: "jdbc:oracle:thin:@localhost:1521:YourDbName" URL 格式: "jdbc:oracle:thin:@localhost:1521:YourDbName"

I think the error is in the port number 1158 in this line:我认为错误出在这一行的端口号 1158 中:

    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1158:ORCL","system", "system");

Normally you connect to an Oracle database using port 1521. Try replacing 1158 with 1521.通常您使用端口 1521 连接到 Oracle 数据库。尝试将 1158 替换为 1521。

Your database may be running the Enterprise Manager on port 1158. That's a web application that you access, often by navigating to https://localhost:1158/em .您的数据库可能在端口 1158 上运行企业管理器。这是您访问的 Web 应用程序,通常通过导航到https://localhost:1158/em The Oracle database itself will typically be listening on port 1521. Oracle 数据库本身通常会侦听端口 1521。

When using JDBC you need to connect direct to the database, not to some web application instead.使用 JDBC 时,您需要直接连接到数据库,而不是连接到某些 Web 应用程序。 The Oracle JDBC driver understands the proprietary binary protocol it uses to communicate with the database, but it doesn't understand the HTTP it gets back from the Enterprise Manager web application. Oracle JDBC 驱动程序理解它用来与数据库通信的专有二进制协议,但它不理解它从企业管理器 Web 应用程序返回的 HTTP。 Hence you get an odd network error.因此,您会收到一个奇怪的网络错误。 You can expect similar random network errors if you attempt to connect the JDBC driver to something else that isn't an Oracle database either.如果您尝试将 JDBC 驱动程序连接到不是 Oracle 数据库的其他东西,您可能会出现类似的随机网络错误。

oracle.jdbc.driver.OracleDriver is deprecated. oracle.jdbc.driver.OracleDriver已弃用。 You will probably have better success by replacing it with oracle.jdbc.OracleDriveroracle.jdbc.OracleDriver替换它可能会取得更好的成功

See: http://www.oracle.com/technetwork/database/enterprise-edition/111070-readme-083278.html and Difference between Oracle jdbc driver classes?请参阅: http : //www.oracle.com/technetwork/database/enterprise-edition/111070-readme-083278.htmlOracle jdbc 驱动程序类之间的区别?

Try this code:试试这个代码:

OracleDataSource ods = new OracleDataSource();    
ods.setUser(DB_USER));    
ods.setPassword(DB_PASSWORD);    
ods.setURL(jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(HOST=myhost)(PORT=1521)(PROTOCOL=tcp))(CONNECT_DATA=(SERVICE_NAME=myorcldbservicename))));    
// New AutoClosable syntax applicable to connection. This syntax will    
// close the connection automatically    
try (OracleConnection connection = (OracleConnection) (ods.getConnection())) {      
 // Statement and ResultSet are AutoClosable by this syntax   
 try (Statement statement = connection.createStatement()) {      
    try (ResultSet resultSet = statement.executeQuery("select sysdate from dual")) {        
      while (resultSet.next())          
           System.out.print("Today's Date is: " + resultSet.getString(1));

    }   
  }
}

暂无
暂无

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

相关问题 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 如何使用JDBC从Oracle 11g获取注释? - How to fetch Comments from a Oracle 11g using 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数据库时,获取IOException“从读取调用中减去一个” - getting IOException “got minus one from a read call” while connecting to oracle 10g database 使用JDBC从Oracle 11g删除记录 - Deleting records from Oracle 11g with JDBC 连接到 Amazon RDS Oracle 实例时如何处理“从读取调用中得到减一”错误 - How to approach a "Got minus one from a read call" error when connecting to an Amazon RDS Oracle instance 如何使用Dataflow的jdbc to Bigquery模板将数据从Oracle 11g第2版传输到Bigquery? - How to transfer data from Oracle 11g release 2 to Bigquery using Dataflow's jdbc to Bigquery template? 无法从Oracle 11g数据库读取表 - Cannot read table from oracle 11g database Oracle 11g 11.2.0.1:不再需要从套接字读取数据 - Oracle 11g 11.2.0.1 : No more data to read from socket Oracle 11g:使用简单的 jdbc 调用将数组作为输入参数传递给 oracle 存储过程 - Oracle 11g: Pass array as input parameter to an oracle stored procedure using simple jdbc call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM