Groovy uses idea to build a groovy simple demo-to write a simple groovy output demo and Jdbcdemo

Source: Internet
Author: User

1, first download a groovy SDK, download the address point I;
2, unzip the groovy SDK that you downloaded; Remember this decompression address and use it later;
3, create a new groovy project with Idea

4, project structure as shown

5, because we want to download the jar package, we are here with Maven management, create a new Pom.xml file, the code in the file can copy the following code;

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 Http://maven.apache . org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <!--artifactid is the name of your own project, you can change it--&
    Gt <groupId>com.platform</groupId> <artifactId>GroovyJDBCDemo</artifactId> <version> 

    1.0.0</version> <packaging>war</packaging> <!--<packaging>jar</packaging>--> <!--name here is your demo name, you can change--> <name>Groovy-JDBCDemo</name> <description>project for Gr Oovy-jdbcdemo</description> <!--notice-dependent Jar pack--> <dependencies> <!--https://mvnrep Ository.com/artifact/org.codehaus.groovy/groovy-all--> <dependency> <groupid>org.codeh
  Aus.groovy</groupid>          <artifactId>groovy-all</artifactId> <version>2.6.0-alpha-2</version> </dependency> <!--Https://mvnrepository.com/artifact/mysql/mysql-connector-java--> &LT;DEP Endency> <groupId>mysql</groupId> <artifactid>mysql-connector-java</artifa ctid> <version>8.0.8-dmr</version> </dependency> </dependencies> </ Project>

Project used jar Bag is inside, after configuration, in the Pom.xml file right, select a conversion to MAVEN Project command, specific because I forget the word, no screenshot, the phrase is very simple, basic see can know;

5, then create a new groovy class, note that this is not Java class;

I have created a new Learngroovy.groovy file here, printing a basic statement:

Package Groovy

class Learngroovy {
    static void main (args) {
        println "Hello world!";
    }
}

6, the second demo is JDBC Connection, a new Groovyjdbcdemo.groovy project, this project is the database in the user ID and user name printed out the code is as follows:

package Groovy import groovy.sql.Sql; Class Groovyjdbcdemo {static void main (args) {//list operation list<string> List = new ARRAYLIST<&G
        t; ();
        List.add ("a");
        List.add ("B");

        println list;
        Map operation, def means not to emphasize variable type, it means a variable, similar to the Var def map in js = [' x ': 1, ' Y ': 4] map.put ("a", 8);

        println map; Sql.newinstance (string url, string user, string password, string driverclassname)//Incoming several parameters are basically the original Jdbc.properitie s inside the contents of the configuration file, I used is MySQL, due to confidentiality, inconvenient disclosure, you can use their own MySQL database address, username and password;//string driverclassname= "Com.mysql.jdbc.Driver" This is to be revealed to everyone, haha sql sql = sql.newinstance ("Jdbc:mysql://**.mysql.rds.aliyuncs.com:3306/**?useunicode=true&chara

        Cterencoding=utf-8 "," UESR "," Password "," Com.mysql.jdbc.Driver "); Sql.eachrow ("SELECT * from Sys_t_user") {println it.id + ": + It.name}}} 

Because the MySQL database address is not convenient to open, you can use their own MySQL database address, username, password; the second demo screenshot is as follows:

In fact, when we connect JDBC, we typically configure a configuration file like Jdbc.properities in the configuration file, and then configure JDBC information in the configuration file, as follows:

Datasource.master.driverclassname=com.mysql.jdbc.driver
Datasource.master.dialect=mysql
Datasource.master.scanfolder=mysql
Datasource.master.url=jdbc:mysql://localhost:3306/fxrj?useunicode=true &characterencoding=utf-8
datasource.master.username=root
datasource.master.password=123456

and agile development, directly to the above the main information, written to the SQL object inside, because just get started, temporarily do not do product theory;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.