`

Grails, MySQL : Cannot create PoolableConnectionFactory

    博客分类:
  • Java
阅读更多

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 plugin: Calendar

    NULL 博文链接:https://search.iteye.com/blog/386023

    the definitive guide to grails 2

    详细介绍grails框架的奥秘,英文版你值得拥有

    grails 开发框架-4

    grails1.0开发框架4 类似于ruby on rails的框架。

    Grails: A Quick-Start Guide

    In Grails: A Quick-Start Guide, you’ll see how to use Grails by iteratively building an unique, working application. By the time we’re done, you’ll have built and deployed a real, functioning ...

    testwebsocket-grails3:Grails 3 springboot websocket 示例

    testwebsocket-grails3 这是一个基本的 Grails 3 应用程序,它尝试通过 Spring Boot 使用 websockets。成功:我们使用新的 WebSocketConfigurer 以及传统的默认 Java Websockets 工作的 websockets: 有两个索引页,...

    Grails : A Quick-Start Guide

    Java web development is notoriously tedious, but help is on the way: Grails. Using the principle of convention-over-configuration and the dynamic Groovy programming language, Grails takes the pain out...

    grails 连接mysql

    这个例子实现了用grails 连接mysql 数据库,并且把内容显示出来,可以增删除改,下载这个例子后大家要把jdk tomcat grails环境搭好,然后用grails run-app来执行,也可以用其它的开发工具,本人用的是netbeans

    grails-pjax:Grails Pjax插件云可帮助您在Grails中使用pjax

    Grails Pjax插件Pjax在Grails中。 Pjax类似于(turbolinks)[ ,在'A'标签,按钮和表单上工作。 参见_pjaxHeader grails templtate文件中的演示代码。 ## Pjax是什么? Pjax是一个jQuery插件,它使用ajax和pushState...

    grails-core:Grails Web应用程序框架

    建置状态 ...ils子 是用于使用编程语言构建Web应用程序的... grails create-app sampleapp cd sampleapp grails run-app 要构建Grails,请克隆此GitHub存储库并执行安装Gradle目标: git clone https://github.com/grails

    Grails-MyBatis:用于 Grails 框架的 MyBatis 插件

    Grails-MyBatis 用于 Grails 框架的 MyBatis 插件 基于原始 Grails-iBatis 插件:Brian Sanders ( ) Grails 插件主页: : 修改: 命名约定的一些变化 添加了对多个数据源的完全支持 Grails 2.0 插件重构 最小 ...

    grails开发环境配置及应用开发

    详细讲解grails开发环境配置。 详细讲解grails连接mysql数据库,crud开发

    grails-data-mapping:GORM-Groovy对象映射

    GORM(Grails对象映射) [Grails] [Grails]是用于使用[Groovy] [Groovy]编程语言构建Web应用程序的框架。 该项目为Hibernate和NoSQL数据存储上的GORM的新实现提供了GORM API管道。 [Grails]: : [Groovy]: : ...

    grails-boot:Grails 与 Spring Boot 的集成

    grails-boot Grails 与 Spring Boot 的集成GORM Spring Boot 插件已移至

    grails-cucumber:Grails的Cucumber插件

    要运行Cucumber功能,可以通过以下命令之一调用grails: grails test-app functional:cucumber grails test-app :cucumber Cucumber功能和步骤应该在“ test/functional文件夹中 步骤实现如下所示: import ...

    精通Grails:创建自定义插件

    本文内容包括:ShortenUrl插件简介创建TinyUrl类测试TinyUrl类创建IsGd类创建ShortenUrl服务打包并部署插件结束语下载参考资料在这个“精通Grails”系列中,ScottDavis将向您展示如何创建您自己的Grails插件。...

    Grails Grails Grails

    Grails Grails Grails Grails Grails

    Grails.in.Action.2009.pdf

    Grails in Action is a comprehensive introduction to the Grails framework covering the nuts and bolts of all core Grails components: controllers, views, services, webflows, taglibs, Ajax, and plugins. ...

    grails-shiro-ui:Grails Shiro UI 插件

    Grails Shiro UI 插件 请参阅。

    grails-koans:用于测试驱动学习的 Grails 插件

    圣杯公案 这是什么? 这是一个未来的grails 应用程序: 针对测试驱动学习 灵感来自 项目状态 自述文件 各种各样的 当前 grails 目标版本:2.4.x

Global site tag (gtag.js) - Google Analytics