lllrc
2019-04-11 18:13c3p0连接数据库提示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条回答
为你推荐
- 项目移植出了点问题
- 数据库
- mysql
- 0个回答
- 开启服务器一直显示“Access denied for user 'root'@'localhost' (using password: YES)”
- java
- tomcat
- eclipse
- jar
- mysql
- 3个回答
- tomcat 404问题,console出的问题有关于mysql数据库连接问题,账号密码错误等问题。萌新求帮助!!
- 数据库
- 密码
- mysql
- tomcat
- 3个回答
- tomcat 404 问题,萌新完全措手无助!
- 应用
- eclipse
- 5个回答
- JAVA SSH开发的网站后台部署到阿里服务器时,连不上数据库
- mysql
- 3个回答
换一换