小编Muh*_*Haq的帖子

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 错误即使在导入库后

我已经导入了我的库“mysql-connector-java-5.1.39”,正如大多数人回答的完全相同的问题,但我仍然收到此错误

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Run Code Online (Sandbox Code Playgroud)

这是测试类的代码

package database;

import java.sql.Connection;
import java.sql.DriverManager;

public class Main {

    public static void main(String[] args) throws Exception {
        getConnection();
    }

    public static Connection getConnection() throws Exception {
        try{
            String driver="com.mysql.jdbc.Driver";
            String url="jdbc:mysql://localhost:3306/test";
            String username="root";
            String password="root";
            Class.forName(driver);
            Connection conn= DriverManager.getConnection(url,username,password);
            System.out.println("connected");
            return conn;
        }
        catch (Exception e){
            System.out.println(e);
        }
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

日食目录

使用 mac 操作系统。

java mysql database eclipse jdbc

7
推荐指数
1
解决办法
2万
查看次数

如何在完全基于功能组件的 React 应用程序中获取元素的大小?

我有一个完全用功能组件构建的 React 应用程序。我想在屏幕上呈现元素后获取元素的高度,以相应地更改其父元素的大小。

有基于类的应用程序的解决方案,但我找不到任何用于功能组件的解决方案。

我从答案中尝试了这个解决方案,但它没有运行 useEffect 钩子

这是从我的组件中提取的代码

import React, {useRef, useEffect} from 'react';
import {
    MenuContainer,
    GrayBox,
    Wrapper

} from '../LayersMenu/LayerMenu.styles';


export const Component = ({ category, showStatistics }) => {
    const grayBoxRef= useRef(null);
    const wrapperRef= useRef(null);
    const testRef= useRef(null);
    useEffect(()=>{
        const height = wrapperRef.current.offsetHeight;
        console.log(height,'check');
      }, [wrapperRef])
    useEffect(()=>{
        const height = testRef.current.offsetHeight;
        console.log(height,'check2');
    },[testRef]);
    return (
        <MenuContainer ref={testRef}>
            <GrayBox ref={grayBoxRef}>
                <Wrapper ref={wrapperRef} hasAnyAllowedStats={showStatistics}>
                </Wrapper>
            </GrayBox>
        </MenuContainer>
    );
};
Run Code Online (Sandbox Code Playgroud)

PS:接受的答案对我的答案不起作用,但它适用于他在答案中添加的项目,所以我猜我的项目结构有问题或不完全确定。

非常感谢回答

javascript reactjs styled-components react-functional-component

4
推荐指数
1
解决办法
5690
查看次数