5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GroovyでJDBC接続備忘録

Posted at

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)
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?