Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Created February 9, 2013 20:12
Show Gist options
  • Save jarek-przygodzki/4746892 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/4746892 to your computer and use it in GitHub Desktop.
Howto connect to PostgreSQL DB in Groovy
import groovy.sql.Sql
def dbUrl = "jdbc:postgresql://localhost/test-db"
def dbUser = "test"
def dbPassword = "test"
def dbDriver = "org.postgresql.Driver"
def sql = Sql.newInstance(dbUrl, dbUser, dbPassword, dbDriver)
@mecca831
Copy link

mecca831 commented Jul 5, 2017

Grab the Postgres dependencies if you run into ClassNotFoundException for the driver:

@GrabConfig(systemClassLoader=true)
@Grab(group='org.postgresql', module='postgresql', version='9.4-1205-jdbc42')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment