eclipse利用jdbc连接mysql连接不起

运行截图如下

img


代码如下
package student.community.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Properties;

public class JdbcManager {
private static Connection connection;
private Statement statement;
public static Connection getConn() {
if(connection != null ) {
return connection;
}

    try {
        Class.forName("com.mysql.jdbc.Driver");
        String url="jdbc:mysql://localhost:3306/communitity";
        String user="admin";
        String password="test123";
        Connection conn=DriverManager.getConnection(url,user,password);
        connection = conn;
        return conn;
    } catch (Exception e) {
        e.printStackTrace();
    }
    
    return null;
}


public synchronized int executeUpdate(String sql){
    int result = 0;
    try {
        statement = connection.createStatement();
        result = statement.executeUpdate(sql);                    
        connection.commit();
    } catch (SQLException e) {
        System.out.println("获取数据错误");    
    }    
    return result;
}


public synchronized int executeUpdate(String sql, List<Object> params){
    int result = 0;
    PreparedStatement statement = null;
    try {
        statement = connection.prepareStatement(sql);
        if(params!=null && params.size()>0){
            for(int i =1 ;i< params.size()+1;i++){
                statement.setObject(i,params.get(i-1));
            }
        }
        result = statement.executeUpdate();
        connection.commit();
    } catch (SQLException e) {
        System.out.println("获取数据错误");
    }finally {
        if(statement != null ){
            try {
                statement.close();
            } catch (SQLException e) {
                System.out.println("获取数据错误");
            }
        }
    }
    return result;
}


public synchronized void close(){
    if(statement != null){
        try {
            statement.close();
            statement = null;
        } catch (SQLException e) {
            System.out.println("获取数据错误");    
        }
    }
    
    if(connection != null){
        try {
            connection.close();
            connection = null;
        } catch (SQLException e) {
            System.out.println("");    
        }
    }
}
    

public static void closeConnection() {
    if(connection!=null) {
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

}

jdbc连接数据库的主要方式是try catch方法吗

数据库密码可能错了,好好检查一下