Search code examples
javasqljdbcderby

Java SQL expected 6 bytes and received 0 error


I am getting this error: "Insufficient data while reading from the network - expected a minimum of 6 bytes and received only 0 bytes. The connection has been terminated." When I try to connect to my data base. I can not seem to find any solution that works. Could you guys give me a hand?

    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;
    }
}

Here is the stack trace:

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


Solution

  • It looks like I found out what is going on. It is due to my own confusion. I am trying to connect to a Microsoft SQL database. Thus I need the sqljdbc driver not derby. This has resolve my issue. Thanks for the help guys.