台灣最大程式設計社群網站
線上人數
1137
 
會員總數:246315
討論主題:189843
歡迎您免費加入會員
討論區列表 >> Java >> Java連結資料庫發生錯誤:End of stream was detected on a read
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
Java連結資料庫發生錯誤:End of stream was detected on a read
價值 : 100 QP  點閱數:814 回應數:1
樓主

阿觀
初學者
1 2
92 2
發送站內信

一樣的程式連結其他主機的資料庫都正常,
但唯獨某一台就會出錯,但刻意將SQL改短一點就正常,
請問各位是否有遇過類似的問題,是DB Server需做什麼設定嗎?

我的環境為:
SQL Server 2012
Tomcat 5.5
JDK 1.8

程式碼如下:
<%@ page contentType="text/html; charset=UTF-8" language="java"
import="java.sql.*" errorPage="" %>
<%
String sql = "SELECT 1 AS T Union SELECT 2 AS T Union SELECT 3 AS T \n";
sql += "Union SELECT 4 AS T Union SELECT 5 AS T Union SELECT 6 AS T\n";
sql += "Union SELECT 4 AS T Union SELECT 5 AS T Union SELECT 6 AS T\n";
.....(一直重覆UNION 幾次,讓SQL長一點)
sql += "Union SELECT 4 AS T Union SELECT 5 AS T Union SELECT 6 AS T\n";

System.out.print(sql);

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String connStr = "jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=DBName;User=UserName;Password=Pwd;";
Connection con = DriverManager.getConnection(connStr);

Statement smt = con.createStatement();
ResultSet rst = smt.executeQuery(sql);

rst.close(); smt.close(); con.close();
%>

錯誤訊息如下:
javax.servlet.ServletException: [Microsoft][SQLServer 2000 Driver for JDBC]End of stream was detected on a read.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.test1_jsp._jspService(test1_jsp.java:101)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

搜尋相關Tags的文章: [ End of stream was detected on a read ] ,
本篇文章發表於2017-12-01 14:44
1樓
作者回應

阿觀
檢舉此回應
升級為 SQL Server JDBC driver version 6.2.2. 之後,問題已經解決,謝謝各位的幫忙。
本篇文章回覆於2017-12-03 00:32
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.