我收到此错误:“从网络读取时数据不足 - 预计至少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:从网络读取时数据不足 - 预计至少6个字节,仅接收0个字节。连接已终止。 at org.apache.derby.client.am.SQLExceptionFactory.getSQLException(未知来源) at org.apache.derby.client.am.SqlException.getSQLException(未知来源) 在org.apache.derby.jdbc.ClientDriver.connect(未知来源) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) 在RetrieveData.HistoryActual(RetrieveData.java:27) 在BookToGoals。(BookToGoals.java:34) 在Console.Console(Console.java:96) 在Console.access $ 0(Console.java:47) 在Console $ 1.run(Console.java:43) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) 在java.awt.EventQueue.access $ 500(未知来源) 在java.awt.EventQueue $ 3.run(未知来源) 在java.awt.EventQueue $ 3.run(未知来源) 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) 引起:ERROR 08006:从网络读取时数据不足 - 预计至少6个字节,仅接收0个字节。连接已终止。 在org.apache.derby.client.net.Reply.fill(未知来源) 在org.apache.derby.client.net.Reply.ensureALayerDataInBuffer(未知来源) 在org.apache.derby.client.net.Reply.readDssHeader(未知来源) 在org.apache.derby.client.net.Reply.startSameIdChainParse(未知来源) at org.apache.derby.client.net.NetConnectionReply.readExchangeServerAttributes(Unknown Source) 在org.apache.derby.client.net.NetConnection.readServerAttributesAndKeyExchange(未知来源) 在org.apache.derby.client.net.NetConnection.flowServerAttributesAndKeyExchange(未知来源) 在org.apache.derby.client.net.NetConnection.flowUSRIDPWDconnect(未知来源) 在org.apache.derby.client.net.NetConnection.flowConnect(未知来源) 在org.apache.derby.client.net.NetConnection。(未知来源) 在org.apache.derby.client.net.ClientJDBCObjectFactoryImpl.newNetConnection(未知来源) ......还有22个
答案 0 :(得分:0)
看起来我发现了正在发生的事情。这是由于我自己的困惑。我正在尝试连接到Microsoft SQL数据库。因此我需要sqljdbc驱动程序而不是derby。这解决了我的问题。谢谢你的帮助。