
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
def sql = sql.newInstance("jdbc:MysqL://localhost:3306/mydb","user","pswd","com.MysqL.jdbc.Driver")// delete table if prevIoUsly createdtry { sql.execute("drop table PERSON")} catch(Exception e){}// create tablesql.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 tabledef 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 okdef results = sql.firstRow("select firstname,lastname from PERSON where ID=1").firstnamedef expected = "James"assert results == expected// allow resultSets to be able to be changedsql.resultSetConcurrency = java.sql.ResultSet.CONCUR_UPDAtable// change the datasql.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 workedresults = sql.firstRow("select firstname,lastname from PERSON where ID=1").firstnameexpected = "JamesJames"assert results == expected 以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的groovy控作sql的高级用法全部内容,希望文章能够帮你解决groovy控作sql的高级用法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)