Grails, MySQL : Cannot create PoolableConnectionFactory

本文主要是介绍Grails, MySQL : Cannot create PoolableConnectionFactory,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Ok, You read this post I assume you face the same problem I faced.

Quick Solution :

If this is your MySQL Connection URL :

“jdbc:mysql://localhost/DN_NAME”

Change it to

“jdbc:mysql://127.0.0.1/DB_NAME”

Understanding the solution :

Recently, I am developing a grails application. I was using the default in memory HSQLDB, as it is wonderful for changing the database design frequently. But, as I felt stability in the project I wanned to move the project to the next level where data get persisted. Hence, I tried to move to MySQL Database by modifying the DataSource.groovy File.

dataSource {
pooled = true
//    driverClassName = “org.hsqldb.jdbcDriver”
//    username = “sa”
//    password = “”

// MySQL Database configurations
driverClassName = “com.mysql.jdbc.Driver”
username = “root”
password = “123456″
}

And result was a very long exception

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager’: Cannot resolve reference to bean ‘sessionFactory’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory’: Cannot resolve reference to bean ‘hibernateProperties’ while setting bean property ‘hibernateProperties’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘hibernateProperties’: Cannot resolve reference to bean ‘dialectDetector’ while setting bean property ‘properties’ with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘dialectDetector’: Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

So, I tried to Google on PoolableConnectionFactor .. But Results was either

Change /etc/hosts.allow and check /etc/hosts

or

Some changes in /etc/my.cnf and grant access to the database user

And they all failed. So I created a new Java Project in NetBeans IDE, added the JDBC Driver Jar file, and wrote the following code:

String dbUrl = “jdbc:mysql://localhost:3306/DB_NAME”;
Class.forName ( “com.mysql.jdbc.Driver” );
Connection connection = DriverManager.getConnection ( dbUrl , “root” , “123456″ );

So, the following single exception appeared :

Dec 5, 2009 9:02:41 AM testmysql.Main main
SEVERE: null
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

So, I Googled again and I found this post

http://forums.sun.com/thread.jspa?threadID=5339538

Which is long, and here is the main point of it :

Re: Communication link failure!!!!
Mar 16, 2009 3:49 PM (reply 8 of 12)  (In reply to #7 )
I’m happy to say that I resolved the issue. I replaced localhost with 127.0.0.1 and it worked perfectly. I’ve also checked what the browser gives as localhost and it’s the IPv6 localhost (to anyone who might be experiencing the same issue that’s 0:0:0:0:0:0:0:1) not the IPv4 one, so that was the problem. Not sure why this machine defaults to IPv6 though.

So, It seams the PC is defaulting to IPv6 not IPv4

and the solution is as I said above

Change the MySQL Connection URL from localhost to 127.0.0.1 (or whatever your localhost IP Address is )

NOTE: you can find you localhost IP Address in /etc/hosts

NOTE: If you use openSuse Linux ( Like I Do ) and you want to disable IPv6, you can do so using

Yast-> Network Manager

Wish you best of luck.

———————————————————————————————

New Updates :

I had another PoolableConnectionFactory exception. This time because I had reinstalled my Linux system, so my databases were gone. I got the following exception

Cannot create PoolableConnectionFactory (Unknown database ‘DB_NAME‘):
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database ‘DB_NAME

Because, there was no Database scheme in the mysql database engine. So, to solve this:

  1. In console window type “mysql -u root -p” if your mysql username is root and you have a password.
  2. Create new database using “create database DB_NAME”.
  3. Exit the mysql console as you don’t need it, using “exit” command.

Now, you can restart your grails application and this exception will not show up again.

Wish you best of luck.

这篇关于Grails, MySQL : Cannot create PoolableConnectionFactory的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/400727

相关文章

MySQL 多表连接操作方法(INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL OUTER JOIN)

《MySQL多表连接操作方法(INNERJOIN、LEFTJOIN、RIGHTJOIN、FULLOUTERJOIN)》多表连接是一种将两个或多个表中的数据组合在一起的SQL操作,通过连接,... 目录一、 什么是多表连接?二、 mysql 支持的连接类型三、 多表连接的语法四、实战示例 数据准备五、连接的性

MySQL中的分组和多表连接详解

《MySQL中的分组和多表连接详解》:本文主要介绍MySQL中的分组和多表连接的相关操作,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录mysql中的分组和多表连接一、MySQL的分组(group javascriptby )二、多表连接(表连接会产生大量的数据垃圾)MySQL中的

MySQL 中的 JSON 查询案例详解

《MySQL中的JSON查询案例详解》:本文主要介绍MySQL的JSON查询的相关知识,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录mysql 的 jsON 路径格式基本结构路径组件详解特殊语法元素实际示例简单路径复杂路径简写操作符注意MySQL 的 J

Windows 上如果忘记了 MySQL 密码 重置密码的两种方法

《Windows上如果忘记了MySQL密码重置密码的两种方法》:本文主要介绍Windows上如果忘记了MySQL密码重置密码的两种方法,本文通过两种方法结合实例代码给大家介绍的非常详细,感... 目录方法 1:以跳过权限验证模式启动 mysql 并重置密码方法 2:使用 my.ini 文件的临时配置在 Wi

MySQL重复数据处理的七种高效方法

《MySQL重复数据处理的七种高效方法》你是不是也曾遇到过这样的烦恼:明明系统测试时一切正常,上线后却频频出现重复数据,大批量导数据时,总有那么几条不听话的记录导致整个事务莫名回滚,今天,我就跟大家分... 目录1. 重复数据插入问题分析1.1 问题本质1.2 常见场景图2. 基础解决方案:使用异常捕获3.

SQL中redo log 刷⼊磁盘的常见方法

《SQL中redolog刷⼊磁盘的常见方法》本文主要介绍了SQL中redolog刷⼊磁盘的常见方法,将redolog刷入磁盘的方法确保了数据的持久性和一致性,下面就来具体介绍一下,感兴趣的可以了解... 目录Redo Log 刷入磁盘的方法Redo Log 刷入磁盘的过程代码示例(伪代码)在数据库系统中,r

mysql中的group by高级用法

《mysql中的groupby高级用法》MySQL中的GROUPBY是数据聚合分析的核心功能,主要用于将结果集按指定列分组,并结合聚合函数进行统计计算,下面给大家介绍mysql中的groupby用法... 目录一、基本语法与核心功能二、基础用法示例1. 单列分组统计2. 多列组合分组3. 与WHERE结合使

Mysql用户授权(GRANT)语法及示例解读

《Mysql用户授权(GRANT)语法及示例解读》:本文主要介绍Mysql用户授权(GRANT)语法及示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql用户授权(GRANT)语法授予用户权限语法GRANT语句中的<权限类型>的使用WITH GRANT

Mysql如何解决死锁问题

《Mysql如何解决死锁问题》:本文主要介绍Mysql如何解决死锁问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录【一】mysql中锁分类和加锁情况【1】按锁的粒度分类全局锁表级锁行级锁【2】按锁的模式分类【二】加锁方式的影响因素【三】Mysql的死锁情况【1

SQL BETWEEN 的常见用法小结

《SQLBETWEEN的常见用法小结》BETWEEN操作符是SQL中非常有用的工具,它允许你快速选取某个范围内的值,本文给大家介绍SQLBETWEEN的常见用法,感兴趣的朋友一起看看吧... 在SQL中,BETWEEN是一个操作符,用于选取介于两个值之间的数据。它包含这两个边界值。BETWEEN操作符常用