会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133515个问题
微服务/第十阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 33437楼
Python 全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 33438楼

maven_demo2.zip


运行测试dao方法


显示结果


com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.


at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:828)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:448)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)

at java.sql.DriverManager.getConnection(DriverManager.java:664)

at java.sql.DriverManager.getConnection(DriverManager.java:247)

at com.itbaizhan.dao.StudentDao.findAll(StudentDao.java:29)

at com.itbaizhan.dao.StudentDaoTest.testFindAll(StudentDaoTest.java:12)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)

at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)

at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)

at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)

at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)

at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)

at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)

at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)

at org.junit.runners.ParentRunner.run(ParentRunner.java:363)

at org.junit.runner.JUnitCore.run(JUnitCore.java:137)

at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)

at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)

at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)

at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151)

at com.mysql.cj.exceptions.ExceptionFactory.createCommunicationsException(ExceptionFactory.java:167)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:89)

at com.mysql.cj.NativeSession.connect(NativeSession.java:120)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:948)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:818)

... 29 more

Caused by: java.net.UnknownHostException: student

at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)

at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:929)

at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1324)

at java.net.InetAddress.getAllByName0(InetAddress.java:1277)

at java.net.InetAddress.getAllByName(InetAddress.java:1193)

at java.net.InetAddress.getAllByName(InetAddress.java:1127)

at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:133)

at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63)

... 32 more



Process finished with exit code -1


JAVA 全系列/第七阶段:项目管理与SSM框架/Maven 33439楼
Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 33440楼
Python 全系列/第七阶段:网页编程基础/CSS 样式 33441楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/MySQL数据库 33442楼
Python 全系列/第四阶段:函数式编程和核心特性/生成器、迭代器、动态性 33444楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 33445楼
Python 全系列/第八阶段:轻量级Web开发利器-Flask框架/虚拟环境 33446楼

window.onload = function() {
    waterFlow();
    // 准备上拉加载的数据
    var dataImage = {
        data: [
            { src: "./images/1.jpeg" },
            { src: "./images/2.jpeg" },
            { src: "./images/3.jpeg" },
            { src: "./images/4.jpeg" },
            { src: "./images/5.jpeg" },
            { src: "./images/6.jpeg" },
            { src: "./images/7.jpeg" },
            { src: "./images/8.jpeg" },
            { src: "./images/9.jpeg" },
            { src: "./images/10.jpeg" },
            { src: "./images/11.jpg" },
        ]
    };
    window.onscroll = function() {
        if (checkReachBottom()) {
            console.log("hhh");
            var parentContainer = document.querySelector(".container");
            for (var i = 0; i < dataImage.data.length; i++) {
                var img = document.createElement("img");
                img.setAttribute("src", dataImage.data[i].src);
                var boximg = document.createElement("div");
                boximg.setAttribute("class", "boximg");
                boximg.appendChild(img);
                var box = document.createElement("div");
                box.setAttribute("class", "box");
                box.appendChild(boximg);
                parentContainer.appendChild(box);

            }
            // 新加载的数据要添加瀑布流效果
            waterFlow();
        }
    }
};
// 1. 动态设置页面左右居中
function waterFlow() {
    // 获取父级容器
    var parentContainer = document.querySelector(".container");
    // console.log(parentContainer);
    //获取所有子元素
    var allChild = document.querySelectorAll(".box");
    // console.log(allChild);
    //获取屏幕宽度
    var screenWidth = document.documentElement.clientWidth;
    //获取一个图片容器的宽度
    var childWidth = allChild[0].offsetWidth;
    //计算屏幕水平方向最多能摆放的图片个数
    var rowsNum = Math.floor(screenWidth / childWidth) - 1;
    // 让左右居中
    parentContainer.style.cssText = "width:" + rowsNum * childWidth + "px;margin:0 auto;";

    getMinHeightOfCols(allChild, rowsNum);
};


// 2. 动态设置图片位置
function getMinHeightOfCols(allChild, rowsNum) {
    //存储每一列的高度
    var colsHeightArr = [];
    for (var i = 0; i < allChild.length; i++) {
        // 判断取出第一行的图片,获取图片对应的高度,放入到数组中
        if (i < rowsNum) { //i=6
            // 获取当前图片的高度
            colsHeightArr[i] = allChild[i].offsetHeight;
        } else {
            // 获取列高度最小的值
            var minHeightOfCols = Math.min.apply(null, colsHeightArr);
            // 获取最小值对应的下标
            var minHeightOfIndex = colsHeightArr.indexOf(minHeightOfCols);
            // 摆放第二张图片的位置
            allChild[i].style.position = "absolute";
            allChild[i].style.top = minHeightOfCols + "px";
            allChild[i].style.left = allChild[minHeightOfIndex].offsetLeft + "px";
            // 高度合并
            colsHeightArr[minHeightOfIndex] = colsHeightArr[minHeightOfIndex] + allChild[i].offsetHeight;

        }
    }
};

// 3. 判断页面触底
// 逻辑:滚动高度+视口高度=文档总高度
// 业务:滚动高度+视口高度>文档总高度-100px(或者是最后一张图片的高度)
function checkReachBottom() {
    // 获取滚动高度
    var scrollHeight = document.documentElement.scrollTop;
    // 获取视口高度
    var pageHeight = document.documentElement.clientHeight;
    // 获取最后一个元素
    var allChild = document.querySelectorAll(".box");
    var lastChildTop = allChild[allChild.length - 1].offsetTop; //最后一个元素
    return lastChildTop < pageHeight + scrollHeight ? true : false;
}

老师,为什么我把网页缩小,上拉加载就能成功,网页最大化不行呢?

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 33448楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术 33450楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637