LoginSignup
1
0

More than 5 years have passed since last update.

GroovyでのDB処理でわからなかった奴ら。

Last updated at Posted at 2012-10-29

GroovyでのDB処理をまとめてて、わからなかった奴ら。
上はともかく、下のdatasetについてはfumokmmさんの所で紹介されているやりかたそのままだから間違ってないと思うんですが。。。

import groovy.sql.Sql

def sql = Sql.newInstance("jdbc:mysql://localhost:3309/test", "yamap", "yamap", "com.mysql.jdbc.Driver")

// Listを返すexecuteInsert というのもあったけど何が返ってくるのかわからない。
//(色々試したけど空のリストしか返ってこない。。。)
def keys =  sql.executeInsert("insert into data (id, name) values (?,?)",['77', 'yamap'])
assert keys == []
println sql.rows("select * from data where id = ?", ["77"])

// dataSetを使用するとsql作ってくれるとかあるらしいけど、例外発生。何が違う??
def dataSet1 = sql.dataSet('data')
def dataSet2 = dataSet1.findAll{it.name == 'yamada'}

// groovy.lang.GroovyRuntimeException: Could not find the ClassNode for MetaClass: org.codehaus.groovy.runtime.metaclass.ClosureMetaClass@1998b7d[class ConsoleScript9$_run_closure1]
println dataSet2.rows()
1
0
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
1
0