You are on page 1of 2

User login application using Grails with MySql

1. Create grails project in eclipse IDE


>New > Others > Grails Project
Enter project name and choose grails version
2. Create domain class
Ex:class User {
String firstName
String lastName
String address
static constraints = {
}
}
3. Create controller class
Ex:class UserController {
def scaffold = User
}
Note:- we can perform curd operations by using scaffold
4. If we want to add permanent server port number then we need to add below line in
BuildConfig.groovy file
grails.server.port.http = 8008
5. If we want to connect with mysql using grails then we have to change the following files
# BuildConfig.groovy
uncomment this following line
> runtime 'mysql:mysql-connector-java:5.1.22'
jar will automatically downloaded
# DataSource.groovy
In this file replace the following code.
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = "root"

}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = "root"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://localhost/mydb?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = "root"
}
}
}
6. Run the app
>right click on the project > Run As > Grails command(run-app)
In console it is showing Server running. Browse to http://localhost:8008/applicationname
7. Open the browser and check your app.
8. Before running this app we need to create database in MySql
>CREATE DATABASE mydb;
In mydb database user table will created.

You might also like