简体   繁体   English

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

Hi I am trying to run a servlet which gets the data from a simple html form and stores in oracle database and displays a message "Data Saved". 嗨,我正在尝试运行一个servlet ,该servlet从简单的html表单获取数据并存储在oracle数据库中,并显示一条消息“ Data Saved”。 I am using Eclipse Luna, Tomcat 7.0 and Oracle 11g Express Edition. 我正在使用Eclipse Luna,Tomcat 7.0和Oracle 11g Express Edition。 When I run the the program I get this error. 当我运行程序时,出现此错误。

java.sql.SQLException: Io exception: Got minus one from a read call during JDBC connection with oracle 11g java.sql.SQLException:Io异常:在与oracle 11g进行JDBC连接期间,从读取调用中减去了一个

Here is my web.xml file 这是我的web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>StudentManagement</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>StudentRegServlet</servlet-name>
    <servlet-class>com.serv.pkg.StudentRegServlet</servlet-class>
    <init-param>
      <description></description>
      <param-name>username</param-name>
      <param-value>scott</param-value>
    </init-param>
    <init-param>
      <param-name>password</param-name>
      <param-value>tiger</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>StudentRegServlet</servlet-name>
    <url-pattern>/stdreg</url-pattern>
  </servlet-mapping>

  <servlet>
  <servlet-name>CourseRegServlet</servlet-name>
  <servlet-class>com.serv.pkg.CourseRegServlet</servlet-class>
  <init-param>
  <param-name>username</param-name>
  <param-value>test</param-value>
   </init-param>

   <init-param>
   <param-name>password</param-name>
   <param-value>test</param-value>
   </init-param>

  </servlet>

  <servlet-mapping>
  <servlet-name>CourseRegServlet</servlet-name>
  <url-pattern>/coursereg</url-pattern>
  </servlet-mapping>

  <context-param>
  <param-name>driver</param-name>
  <param-value>oracle.jdbc.OracleDriver</param-value>
  </context-param>

  <context-param>
  <param-name>url</param-name>
  <param-value>jdbc:oracle:thin:@localhost:8080:XE</param-value>
  </context-param>
</web-app>

My Servlet 我的Servlet

package com.serv.pkg;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;

/**
 * Servlet implementation class CourseRegServlet
 */
@WebServlet("/CourseRegServlet")
public class CourseRegServlet extends GenericServlet {
    private Connection conn; 
    @Override
    public void init(ServletConfig config)throws ServletException
    {
        System.out.println("Executing init method from coursereg.html");
    ServletContext sc = config.getServletContext( );
    String driver=sc.getInitParameter("driver");
    String url=sc.getInitParameter("url");
    String username=config.getInitParameter("username");
    String password=config.getInitParameter("password");

    try {
        Class.forName(driver);
        System.out.println("driver loaded");
        conn=DriverManager.getConnection(url, username, password );
    } catch ( Exception e) {
        System.out.println("catching from init" +e);
    }

    }


    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        System.out.println("Executing service method from coursereg.html");
          int cid = Integer.parseInt(request.getParameter("cid"));
          String c_name = request.getParameter("c_name");
          int fee = Integer.parseInt(request.getParameter("fee"));

          try {
              System.out.println("exe1");
            PreparedStatement stmt=conn.prepareStatement("insert into course values(?,?,?)");
            System.out.println("exe2");
            stmt.setInt(1, cid);
            stmt.setString(2, c_name);
            stmt.setInt(3, fee);
            int i = stmt.executeUpdate();
            if(i!=0){
                System.out.println("course registered");
            }else
            {
                System.out.println("registration failed");
            }
        } catch ( Exception e) {
            System.out.println(e);
        }
          out.println("Data saved");
    }

    public void destroy(){
        try {
            System.out.println("Executing destroy method from coursereg.html");
            conn.close();
        } catch ( Exception e) {
            System.out.println(e);
        }
    }

}

The default port for the database listener is 1521, not 8080 (which is the default HTTP port, from XML DB); 数据库侦听器的默认端口是1521,而不是8080(这是XML DB中的默认HTTP端口); so your URL should be: 因此您的网址应为:

  <param-value>jdbc:oracle:thin:@localhost:1521:XE</param-value>

If your listener is on a non-standard port then use that instead. 如果您的侦听器在非标准端口上,请改用该端口。 Also the :XE part means it'll try to connect with the SID XE. 另外:XE部分意味着它将尝试与SID XE连接。 You might prefer to use the service name, which is hopefully also XE, which would be denoted by a slash instead of a colon: 您可能更喜欢使用服务名称,希望它也是XE,用斜杠而不是冒号表示:

  <param-value>jdbc:oracle:thin:@localhost:1521/XE</param-value>

暂无
暂无

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

相关问题 java.sql.SQLException:Io异常:在与oracle的JDBC连接期间从读取调用中减去了一个 - java.sql.SQLException: Io exception: Got minus one from a read call during JDBC connection with oracle 如何解决从 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? 在与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? 换行章程\\ n给出“java.sql.SQLException:ORA-00911:无效字符\\ n”Oracle 11g - newline charter \n gives “java.sql.SQLException: ORA-00911: invalid character\n” Oracle 11g 异常无法获取JDBC连接; 嵌套异常是java.sql.SQLException:没有为jdbc找到合适的驱动程序:oracle:thin:@localhost:1521:xe - Exception Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@localhost:1521:xe 使用jdbc从Web应用程序连接到Oracle 11g时出现SQL异常 - SQL Exception while connecting to oracle 11g from web application using jdbc 无法连接到Oracle DB,因为java.sql.SQLException而出现错误:Io异常:网络适配器无法建立连接 - Not able to connect to Oracle DB getting error as java.sql.SQLException: Io exception: The Network Adapter could not establish the connection 在连接到oracle 10g数据库时,获取IOException“从读取调用中减去一个” - getting IOException “got minus one from a read call” while connecting to oracle 10g database 连接 oracle 11g 与 java 8 (eclipse) - connection oracle 11g with java 8 (eclipse) 获取JDBC连接失败; 嵌套异常是 java.sql.SQLException: null - Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM