2011年2月19日土曜日

groovyとApache Derbyでビューのみを列挙する

groovyとApache Derbyでビューのみを列挙するには、以下のコードを実行します。

import groovy.sql.Sql
import java.sql.*

sql = Sql.newInstance(
"jdbc:derby:test1db",
"org.apache.derby.jdbc.EmbeddedDriver")

// ビューのみを列挙する
query = """
select tablename from sys.systables
where tabletype = 'V'
"""
sql.eachRow(query){
println("${it.tablename}")
}

// シャットダウン
try
{
Sql.newInstance(
"jdbc:derby:;shutdown=true",
"org.apache.derby.jdbc.EmbeddedDriver")
}
catch(SQLException sqlex)
{
if( sqlex.getSQLState().equals("XJ015") ){
println("shutdown normally.")
}
}


動作環境
groovy 1.7.6, JDK6 Update23, Apache Derby 10.7.1.1

0 件のコメント:

コメントを投稿