Created
June 28, 2018 05:53
-
-
Save ossan-pg/925e0c5eb04cdfc7548bea8a288d90bc to your computer and use it in GitHub Desktop.
DBのテーブルから定期的にレコードを取得してコンソール出力する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
url = 'jdbc:postgresql://localhost:5432/my_db' | |
user = 'username' | |
pass = 'password' | |
driver = 'org.postgresql.Driver' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@GrabConfig(systemClassLoader=true) | |
@Grapes(@Grab(group='org.postgresql', module='postgresql', version='42.2.2')) | |
import groovy.sql.Sql | |
import groovy.util.ConfigObject | |
import groovy.util.ConfigSlurper | |
ConfigObject db = new ConfigSlurper().parse(new File('config.groovy').toURL()) | |
Sql sql = Sql.newInstance(db.url, db.user, db.pass, db.driver) | |
while(true) { | |
String date = new Date().format('HH:mm:ss') | |
sql.eachRow('SELECT * FROM hoge_table WHERE hoge_id = 9999') { | |
println date + ' ' + it | |
} | |
sleep 1000 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment