gpt4 book ai didi

Java SQL 需要 6 个字节并收到 0 个错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:22:08 24 4
gpt4 key购买 nike

我收到此错误:“从网络读取数据时数据不足 - 预计至少 6 个字节,但仅收到 0 个字节。连接已终止。”当我尝试连接到我的数据库时。我似乎找不到任何有效的解决方案。你们能帮我一下吗?

    import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class RetrieveData
{
private String zone;
private String date;
private String userName = "User";
private String password = "Password";
private String serverAdress= "jdbc:derby://Server:1010/Database";
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
RetrieveData(String zoneToPull, String dayToPull)
{
zone = zoneToPull;
date = dayToPull;
}

public int HistoryActual()
{
try
{
Class.forName("org.apache.derby.jdbc.ClientDriver");
con = DriverManager.getConnection(serverAdress, userName, password);
String sql = "SELECT TOP 10 " +
"*" +
"FROM" +
"walks" +
"WHERE"+
"company_id = 'TMS3'";
stmt = con.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next())
{
System.out.println(rs.getString(4) + " " + rs.getString(6));
}
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
finally
{
if (rs != null) try { rs.close(); } catch(Exception e) {}
if (stmt != null) try { stmt.close(); } catch(Exception e) {}
if (con != null) try { con.close(); } catch(Exception e) {}
}
return 0;
}
}

这是堆栈跟踪:

java.sql.SQLNonTransientConnectionException: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes. The connection has been terminated. at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(Unknown Source) at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) at org.apache.derby.jdbc.ClientDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at RetrieveData.HistoryActual(RetrieveData.java:27) at BookToGoals.(BookToGoals.java:34) at Console.Console(Console.java:96) at Console.access$0(Console.java:47) at Console$1.run(Console.java:43) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$500(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Caused by: ERROR 08006: Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes. The connection has been terminated. at org.apache.derby.client.net.Reply.fill(Unknown Source) at org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(Unknown Source) at org.apache.derby.client.net.Reply.readDssHeader(Unknown Source) at org.apache.derby.client.net.Reply.startSameIdChainParse(Unknown Source) at org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttributes(Unknown Source) at org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyExchange(Unknown Source) at org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyExchange(Unknown Source) at org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(Unknown Source) at org.apache.derby.client.net.NetConnection.flowConnect(Unknown Source) at org.apache.derby.client.net.NetConnection.(Unknown Source) at org.apache.derby.client.net.ClientJDBCObjectFactoryImpl.newNetConnection(Unknown Source) ... 22 more

最佳答案

看来我知道发生了什么了。这是由于我自己的困惑。我正在尝试连接到 Microsoft SQL 数据库。因此我需要 sqljdbc 驱动程序而不是 derby。这已经解决了我的问题。谢谢你们的帮助。

关于Java SQL 需要 6 个字节并收到 0 个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38754043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com