`

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

    **Grails插件:Calendar** Grails是一款基于Groovy语言的开源Web应用框架,它简化了Java开发,提供了丰富的功能和灵活的架构。在Grails社区中,开发人员经常创建插件来扩展框架的功能,满足特定的需求。"Calendar...

    the definitive guide to grails 2

    《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...

    grails 开发框架-4

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

    grails3 CAS链接接数据库

    标题中的“grails3 CAS链接接数据库”表明我们要讨论的是如何在Grails 3框架下集成CAS(Central Authentication Service)并实现与数据库的连接。Grails是一个基于Groovy语言的开源Web应用框架,而CAS是一种广泛使用...

    testwebsocket-grails3:Grails 3 springboot websocket 示例

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

    grails-boot:Grails 与 Spring Boot 的集成

    《Grails与Spring Boot的深度集成解析》 在现代Java开发领域,Grails和Spring Boot都是非常流行的框架。Grails作为Groovy语言构建的Web开发框架,以其强大的生产力和灵活的特性受到开发者的喜爱,而Spring Boot则...

    Grails&Groovy学习资料

    Grails和Groovy是两个密切相关的技术,它们在IT领域,尤其是Web开发中扮演着重要角色。Grails是一个基于Groovy语言的开源Web应用框架,它简化了开发过程,提供了丰富的功能,而Groovy则是一种面向Java平台的动态编程...

    转: Eclipse下Grails开发环境搭建步骤

    在本文中,我们将详细探讨如何在Eclipse集成开发环境中搭建Grails开发环境。Grails是一个基于Groovy语言的开源Web应用程序框架,它简化了Java平台上的Web应用开发流程。通过Eclipse,我们可以获得强大的开发工具支持...

    Groovy轻松入门——Grails实战基础篇

    D:\Temp\grails_apps>grails create-app demo Welcome to Grails 0.4.2 - http://grails.org/ Licensed under Apache Standard License 2.0 Grails home is set to: D:\D\MY_DEV\grails Base Directory: D:\...

    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-flyway:Flyway对Grails的支持

    **Grails-Flyway 插件详解:数据库迁移利器** 在现代软件开发中,随着项目的迭代,数据库结构也需要随之变化,以适应业务需求。数据库迁移工具应运而生,它们帮助开发者管理数据库版本,确保在多环境下的数据一致性...

    Grails3配置单独的数据库properties.pdf

    在IT行业中,Grails是一个基于Groovy语言的开源Web应用框架,它简化了Java平台上的开发工作。Grails 3是其一个重要的版本更新,带来了许多改进和新特性。本篇将详细介绍如何在Grails 3中配置单独的数据库properties...

    Grails.2.A.Quick-Start.Guide.pdf

    ### Grails 2: A Quick-Start Guide #### 书籍概览 《Grails 2:快速入门指南》是一本专为希望快速掌握Grails框架的开发者编写的实用指南。本书由Dave Klein与Ben Klein共同编写,通过一个逐步迭代的小项目来介绍...

Global site tag (gtag.js) - Google Analytics