Groovy   发布时间:2022-04-12  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了groovy控作sql的高级用法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

下面是大佬教程code.js-code.com 通过网络收集整理的代码片段。

大佬教程小编现在分享给大家,也给大家做个参

 def sql = sql.newInstance("jdbc:MysqL://localhost:3306/mydb","user","pswd","com.MysqL.jdbc.Driver")

// DELETE TABLE if prevIoUsly created
try {
   sql.execute("drop table PERSON")
} catch(Exception E){}

// create table
sql.execute('''create table PERSON (
    id integer not null priMary key,FirstName varchar(20),LastName varchar(20),LOCATIOn_id integer,LOCATIOn_name varchar(30)
)''')

// Now let's populate the table
def people = sql.dataSet("PERSON")
people.add( firstname:"James",lastname:"Strachan",id:1,LOCATIOn_id:10,LOCATIOn_name:'London' )
people.add( firstname:"Bob",lastname:"Mcwhirter",id:2,LOCATIOn_id:20,LOCATIOn_name:'Atlanta' )
people.add( firstname:"Sam",lastname:"Pullara",id:3,LOCATIOn_id:30,LOCATIOn_name:'California' )

// do a query to check it all worked ok
def results = sql.firstRow("SELEct firstname,lastname from PERSON where id=1").firstname
def expected = "James"
assert results == expected

// allow resultSets to be able to be changed
sql.resultSetConcurrency = java.sql.ResultSet.CONCUR_updatABLE

// change the data
sql.eachRow("SELEct * from PERSON") {
    it.firstname = it.firstname * 2
}

// reset resultSetsConcurrency BACk to read only (no further changes required)
sql.resultSetConcurrency = java.sql.ResultSet.CONCUR_READ_ONLY

// do a query to confirm that our change actually worked
results = sql.firstRow("SELEct firstname,lastname from PERSON where id=1").firstname
expected = "JamesJames"
assert results == expected

大佬总结

以上是大佬教程为你收集整理的groovy控作sql的高级用法全部内容,希望文章能够帮你解决groovy控作sql的高级用法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: