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中的乐观锁与悲观锁

《数据库面试必备之MySQL中的乐观锁与悲观锁》:本文主要介绍数据库面试必备之MySQL中乐观锁与悲观锁的相关资料,乐观锁适用于读多写少的场景,通过版本号检查避免冲突,而悲观锁适用于写多读少且对数... 目录一、引言二、乐观锁(一)原理(二)应用场景(三)示例代码三、悲观锁(一)原理(二)应用场景(三)示例

SQL表间关联查询实例详解

《SQL表间关联查询实例详解》本文主要讲解SQL语句中常用的表间关联查询方式,包括:左连接(leftjoin)、右连接(rightjoin)、全连接(fulljoin)、内连接(innerjoin)、... 目录简介样例准备左外连接右外连接全外连接内连接交叉连接自然连接简介本文主要讲解SQL语句中常用的表

SQL server配置管理器找不到如何打开它

《SQLserver配置管理器找不到如何打开它》最近遇到了SQLserver配置管理器打不开的问题,尝试在开始菜单栏搜SQLServerManager无果,于是将自己找到的方法总结分享给大家,对SQ... 目录方法一:桌面图标进入方法二:运行窗口进入方法三:查找文件路径方法四:检查 SQL Server 安

MySQL 中的 LIMIT 语句及基本用法

《MySQL中的LIMIT语句及基本用法》LIMIT语句用于限制查询返回的行数,常用于分页查询或取部分数据,提高查询效率,:本文主要介绍MySQL中的LIMIT语句,需要的朋友可以参考下... 目录mysql 中的 LIMIT 语句1. LIMIT 语法2. LIMIT 基本用法(1) 获取前 N 行数据(

MySQL 分区与分库分表策略应用小结

《MySQL分区与分库分表策略应用小结》在大数据量、复杂查询和高并发的应用场景下,单一数据库往往难以满足性能和扩展性的要求,本文将详细介绍这两种策略的基本概念、实现方法及优缺点,并通过实际案例展示如... 目录mysql 分区与分库分表策略1. 数据库水平拆分的背景2. MySQL 分区策略2.1 分区概念

MySQL高级查询之JOIN、子查询、窗口函数实际案例

《MySQL高级查询之JOIN、子查询、窗口函数实际案例》:本文主要介绍MySQL高级查询之JOIN、子查询、窗口函数实际案例的相关资料,JOIN用于多表关联查询,子查询用于数据筛选和过滤,窗口函... 目录前言1. JOIN(连接查询)1.1 内连接(INNER JOIN)1.2 左连接(LEFT JOI

MySQL 中查询 VARCHAR 类型 JSON 数据的问题记录

《MySQL中查询VARCHAR类型JSON数据的问题记录》在数据库设计中,有时我们会将JSON数据存储在VARCHAR或TEXT类型字段中,本文将详细介绍如何在MySQL中有效查询存储为V... 目录一、问题背景二、mysql jsON 函数2.1 常用 JSON 函数三、查询示例3.1 基本查询3.2

MySQL中动态生成SQL语句去掉所有字段的空格的操作方法

《MySQL中动态生成SQL语句去掉所有字段的空格的操作方法》在数据库管理过程中,我们常常会遇到需要对表中字段进行清洗和整理的情况,本文将详细介绍如何在MySQL中动态生成SQL语句来去掉所有字段的空... 目录在mysql中动态生成SQL语句去掉所有字段的空格准备工作原理分析动态生成SQL语句在MySQL

MySQL中FIND_IN_SET函数与INSTR函数用法解析

《MySQL中FIND_IN_SET函数与INSTR函数用法解析》:本文主要介绍MySQL中FIND_IN_SET函数与INSTR函数用法解析,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友一... 目录一、功能定义与语法1、FIND_IN_SET函数2、INSTR函数二、本质区别对比三、实际场景案例分

MySQL中的交叉连接、自然连接和内连接查询详解

《MySQL中的交叉连接、自然连接和内连接查询详解》:本文主要介绍MySQL中的交叉连接、自然连接和内连接查询,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、引入二、交php叉连接(cross join)三、自然连接(naturalandroid join)四