Skip to content

Instantly share code, notes, and snippets.

@LCHCAPITALHUMAIN
Forked from jpertino/databaseConnection.groovy
Last active August 29, 2015 14:17

Revisions

  1. @jpertino jpertino created this gist Jan 28, 2011.
    33 changes: 33 additions & 0 deletions databaseConnection.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@

    // PostgreSQL
    @GrabConfig(systemClassLoader=true)
    @Grab('postgresql:postgresql:9.0-801.jdbc4')
    def sql = groovy.sql.Sql.newInstance(
    "jdbc:postgresql://host.example.org/database",
    "username", "password", "org.postgresql.Driver")

    // MySQL
    @GrabConfig(systemClassLoader=true)
    @Grab('mysql:mysql-connector-java:5.1.12')
    def sql = groovy.sql.Sql.newInstance(
    "jdbc:mysql://host.example.org/database",
    "username", "password", "com.mysql.jdbc.Driver")

    // MS SQL Server
    @GrabConfig(systemClassLoader=true)
    @Grab('net.sourceforge.jtds:jtds:1.2.2')
    def sql = groovy.sql.Sql.newInstance(
    "jdbc:jtds:sqlserver://host.example.org/database",
    "username", "password", "net.sourceforge.jtds.jdbc.Driver")

    // HSQLDB embedded
    @GrabConfig(systemClassLoader=true)
    @Grab('org.hsqldb:hsqldb:2.0.0')
    def sql = groovy.sql.Sql.newInstance(
    "jdbc:hsqldb:mem:database", "sa", "", "org.hsqldb.jdbcDriver")

    // H2 embedded
    @GrabConfig(systemClassLoader=true)
    @Grab('com.h2database:h2:1.3.148')
    def sql = groovy.sql.Sql.newInstance(
    "jdbc:h2:mem:database", "sa", "", "org.h2.Driver")