Your cart
  • IMG
    {{cart_item.name}}
    {{cart_item.variation_attribute_name}}: {{cart_item.variation_attribute_label}}
    {{cart_item.item_unit}}: {{ setCurrency(cart_item.price)}}
    {{ setCurrency(cart_item.price*cart_item.quantity)}}
    Invalid quantity more than stock
Total :
{{setCurrency(cart.sub_total)}}

There is no item in the cart. If you want to buy, Please click here.

Step 1: Database connect and Table Migration

Complete Application using Grails 3

Created by :
Grails
tutorial
Programming, Software and application
1090
2020-10-14 16:12:27

In this step we will connect database and create table using Grails domain. For connecting database, just create a database named grailstorial and update in conf/application.yml file

Default

Updated

   dataSource:

    pooled: true

    jmxExport: true

    driverClassName: org.h2.Driver

    username: sa

    password: ''


 dataSource:

      pooled = true

      driverClassName = "com.mysql.jdbc.Driver"

      dialect = org.hibernate.dialect.MySQL5InnoDBDialect


   environments:

    development:

        dataSource:

            dbCreate: create-drop

            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
 
 environments:

    development:

        dataSource:

              dbCreate: update

              url:  "jdbc:mysql://localhost:3306/grailstorial"

              username : "testuser"

              password : "pass123"
 

 

Add the mysql deps as runtime in the dependencies of your build.gradle. E.g.

runtime 'mysql:mysql-connector-java:5.1.36'

 

Create a domain by following command

grails create-domain-class Contact
At now, run the app, if you see a table in the database, then database connection is okay. 
Database connection is okay and we need to modify domain class.   A domain class represents the core model behind in your application and is typically mapped onto database tables. 




class Contact {

    String firstName

    String lastName

    String email

    String city

    String country

    String message

    static constraints = {

    }

}
Run app again and you will see table filed according to domain class defined variable. 
For more about grails domain and constraints - http://docs.grails.org/3.1.1/ref/Domain%20Classes/constraints.html