Grails Cookbook - A collection of tutorials and examples

Groovy SQL Delete Operation Examples

When a record in a database table is not needed anymore then we may want to delete it. There are two ways of deleting a record. One is called logical delete where the record is still in the table but a marker was set in one of the column to tell the application that uses the table to ignore it. The second one is called physical delete where we really delete the record in the databases. SQL provides the delete statement for physical delete. Below are examples on how to perform delete operation using Groovy SQL.

Groovy SQL Update Operation Examples

There are instances when data on a record should be modified. SQL provides update statements for this purpose. Below are examples on how to perform update operation using Groovy SQL.

Groovy SQL Read Operation Examples

Reading data from database tables is one of the most common task in programming. For RDBMS servers that supports SQL, we can use SELECT statements for this purpose. Below are some examples on how to read data from database tables using Groovy SQL.

Groovy SQL Insert Operation Examples

Another common operation when working with database is inserting data. This is simple to achieve using SQL's insert statements. Below are some examples on how to insert data to a database table using Groovy SQL.

Groovy SQL Create Table Examples

One of the first things we do to a database is to create tables. SQL supports data definition language or data description language (DDL). Using SQL "Create" statements, we can create tables in our database. Below is a simple example on how to use Groovy SQL to create a table in the database.

Groovy SQL Database Connection Examples

When working with database in Groovy, the first thing we want to do is to connect to a database server. We will not be able to read or manipulate data unless we have a connection. Below will show a simple example on how to connect to a MySQL database in Groovy.

Groovy String Tokenize Examples

The String class in Groovy has the tokenize() method as a convenient way to tokenize a String or character sequence and return the result as List of String. The given String or character sequence is delimited by whitespace as a default, or can be used passing delimiter as a paramater. Below are some examples on how to use Groovy String's tokenize() method.

Groovy Enum Examples

Enum was introduced in Java to represent a fixed set of constants. Since Groovy is a superset of Java, Enums are also supported in the Groovy programming language. Groovy also adds some enhancements to make working with Enums easier. Below are some examples on how to work with Enums in Groovy.

Groovy Range Examples

Groovy supports a quick way of declaring a list of sequential values using Ranges. In Groovy, a Range can be defined using the .. or ..< notation to declare a list of sequential values. Below are some examples.

Groovy Split Examples

Groovy String has a split() method as a convenience method to split a String or character sequence and return the result as Array of String. The given String or character sequence is split by whitespace as a default, or the given delimiter. Below are some examples on how to use Groovy String's split() method.