驱动程序尚未收到来自服务器Eclipse MYSQL的任何数据包

问题描述

您好,我正在尝试将Eclipse项目与MysqL数据库连接。当它连接时,我收到以下错误消息:

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

这是我的dbconfig.java(我用于连接数据库文件

@Configuration
public class DbConfig {

final boolean REMOTE = true;
final String REMOTE_HOST = "MysqL.mcscw3.le.ac.uk"; 

@Bean
public DriverManagerDataSource dataSource() {
    String path = System.getProperty("user.home") + "/Project.MysqL.properties";
    if (Files.isReadable(Paths.get(path))) {
        Properties MysqLProps = new Properties();
        try {
            MysqLProps.load(new FileInputStream(path));
        } catch (Exception e) {
            e.printstacktrace();
        }

        String dbPassword = MysqLProps.getProperty("dbPassword");
        String user = MysqLProps.getProperty("username");

        try {
            Files.write(Paths.get("gradle/db.conf"),(System.currentTimeMillis() +  ": DbConfig used from " + path + "\n").getBytes(),StandardOpenoption.APPEND,StandardOpenoption.CREATE);
        } catch (IOException e) {
        }

        String host = REMOTE ? "127.0.0.1" : REMOTE_HOST;
        int port = REMOTE ? 3307 : 3306;


        DriverManagerDataSource ds = new DriverManagerDataSource();
        ds.setDriverClassName("com.MysqL.cj.jdbc.Driver");
        ds.setUrl("jdbc:MysqL://" + host + ":" + port + "/" + user);
        ds.setUsername(user);
        ds.setPassword(dbPassword);
        return ds;
    } else {
        try {
            Files.write(Paths.get("gradle/db.conf"),(System.currentTimeMillis() +  ": No DbConfig in " + path + "\n").getBytes(),StandardOpenoption.CREATE);
        } catch (IOException e) {
        }
        throw new RuntimeException("Place your username and passwords in file " + path);
    }
}

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)