我收到此错误:“从网络读取时数据不足-预期至少为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;
    }
}

这是堆栈跟踪:

最佳答案

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

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

10-11 00:17