lllrc 2019-04-11 18:13 采纳率: 0%
浏览 1574
已采纳

c3p0连接数据库提示Access denied for user 'root'@'localhost' (using password: YES)

While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
1,c3p0.properties配置

c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.url=jdbc:mysql://localhost:3306/store38?3useUnicode=true&characterEncoding=utf8
c3p0.user=root
c3p0.password=12345

datasourceUtils

package com.itheima.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;

public class DataSourceUtils {

    private static ComboPooledDataSource ds=new ComboPooledDataSource();

    /**
     * 获取数据源
     * @return 连接池
     */
    public static DataSource getDataSource(){
        return ds ;
    }

    /**
      * 释放资源
     * @param conn
     * @param st
     * @param rs
     */
     public static void CloseResource(Connection conn,Statement st , ResultSet rs){
         closeResultSet(rs);
         closeStaement(st);
         closeConn(conn);
     }

    /**
     * 获取连接
     * @return 连接
     * @throws SQLException 
     */
    public static Connection getConnection() throws SQLException{
        return ds.getConnection();
    }

    /**
      *释放连接 
     * @param conn
     *     连接
     */
     public static void closeConn(Connection conn){
         if(conn!=null){
             try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally{
                conn = null ;
            }
         }
     }

     /**
      * 释放语句执行者
     * @param st
     * 语句执行者
     */
    public static void closeStaement(Statement st){
         if(st!=null){
             try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally{
                st = null ;
            }
         }
     }

    /**
     * 释放结果集
     * @param rs
     * 结果集
     */
    public static void closeResultSet(ResultSet rs){
         if(rs!=null){
             try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }finally{
                rs = null ;
            }
         }
     }

}
  • 写回答

2条回答

  • threenewbee 2019-04-11 18:55
    关注

    密码不正确,所以被拒绝访问了

    参考:https://blog.csdn.net/qq_36675754/article/details/81381341 设置下服务器密码。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已采纳回答 8月29日

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记