Groovyに限らず、データベースに接続する時の書き方を毎回毎回ググっているのでいい加減に自分用メモ。
#PostgreSQL
@GrabConfig(systemClassLoader=true)
@Grapes(
@Grab(group='postgresql', module='postgresql', version='9.1-901.jdbc4')
)
import groovy.sql.Sql
def dbServer = 'localhost'
def dbName = '******'
def dbPort = '******'
def url = "jdbc:postgresql://${dbServer}:${dbPort}/${dbName}"
def user = '*******'
def password = '*******'
def driver = 'org.postgresql.Driver'
def sql = Sql.newInstance(url, user, password, driver)
#MySQL
@GrabConfig(systemClassLoader=true)
@Grapes(
@Grab(group='mysql', module='mysql-connector-java', version='5.1.29')
)
import groovy.sql.Sql
def dbServer = 'localhost'
def dbName = '******'
def dbPort = '******'
def url = "jdbc:mysql://${dbServer}:${dbPort}/${dbName}"
def user = '******'
def password = '******'
def driver = 'com.mysql.jdbc.Driver'
sql = Sql.newInstance(url, user, password, driver)
#Sybase
@GrabConfig(systemClassLoader=true)
@Grapes(
@Grab(group='net.sourceforge.jtds', module='jtds', version='1.3.1')
)
import groovy.sql.Sql
def dbServer = 'localhost'
def dbName = '*****'
def dbPort = '*****'
def url = "jdbc:jtds:sybase://${dbServer}:${dbPort}/${dbName}"
def user = '*****'
def password = '*****'
def driver = 'net.sourceforge.jtds.jdbc.Driver'
def sql = Sql.newInstance(url, user, password, driver)