Grails Script DB Connection parameter storing

Storing Userids / passwords for multiple connections securely in one central file in one’s home directory.

// Load DB settings

def env = System.getenv()

String propfile = "${env['HOME']}/"

def config = new ConfigSlurper().parse(new File(propfile).toURL())

println "Running with DB User ID : " <<

def db

if ( Config.DBTOUPDATE == 'prod' ) {

db = Sql.newInstance(,,, config.db

dbgcrd = Sql.newInstance(,,, confi

} else {

db = Sql.newInstance(,,,

dbgcrd = Sql.newInstance(,,, confi


The format of the config params is :

[gkowalski@scott:~/projects/snpDatabaseImport]$ ls -l ~/

-rwx------+ 1 gkowalski gkowalski 682 Sep 18 12:13

[gkowalski]$ cat ~/

// Development Database settings"devUserid""xxxx""""oracle.jdbc.driver.OracleDriver"

// Production Database settings"prodUserId""xxxxxx""""oracle.jdbc.driver.OracleDriver"

This keeps one from checking in DB passwords into SVN… Also keeps them all in one central spot for updating.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s