import groovy.sql.Sql
sql = Sql.newInstance(
  "jdbc:postgresql://localhost:5432/jtrac", 
   "postgres",
   "postgres", 
   "org.postgresql.Driver")
query = """select 
  current_database() as cdb,
  current_user
"""
sql.eachRow(query){
    // 接続しているDB名
    println "cdb:${it.cdb}"
    // 接続しているユーザ名
    println "current_user:${it.current_user}"
    println "----"
}
動作環境
Groovy 1.6.3, JDK6 Update16, Postgres 8.4.0,
8.4-701JDBC4
関連情報
current_database(), current_user
http://www.postgresql.org/docs/8.4/interactive/functions-info.html
0 件のコメント:
コメントを投稿