eclipse连接mysql--com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not crea

eclipse连接mysql 原本是很简单的事情,但是出了一个问题花费一晚上和一早上才找到答案

前提:Maven pom.xml中dependency有加

    
        mysql
        mysql-connector-java
        8.0.13
    

数据库连接各种写法正确

    private String jdbcURL = "jdbc:mysql://localhost:3306/book_store";
    private String jdbcUsername = "root";
    private String jdbcPassword = " ";
    private Connection jdbcConnection;

try {
            if (jdbcConnection == null || jdbcConnection.isClosed()) {
                Class.forName("com.mysql.jdbc.Driver");
                jdbcConnection = DriverManager.getConnection(
                        jdbcURL, jdbcUsername, jdbcPassword);
                
                System.out.println("MySQL Connect Established!");
            }
        } catch(Exception e) {
            e.printStackTrace();
        }

依然连接不了,像是驱动的问题 ,终于找到这个害人的小婊砸

    Class.forName("com.mysql.jdbc.Driver");
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary

换成 

 Class.forName("com.mysql.cj.jdbc.Driver");

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

windows 开启服务进程方法

services.msc

开启mysql服务

你可能感兴趣的:(programming)