微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决驱动程序尚未收到来自服务器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 举报,一经查实,本站将立刻删除。