楼主: ReneeBK
790 5

【Apache Groovy】Apache Groovy Tutorial [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49497 个
通用积分
53.4454
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

本帖隐藏的内容

Apache Groovy Tutorial.pdf (2.83 MB)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Tutorial apache tutor Tori APA

沙发
ReneeBK 发表于 2017-3-12 10:37:55 |只看作者 |坛友微信交流群

Connecting to the database

  1. The Sql class has a newInstance factory method which takes these parameters. You would typically use it as follows:

  2. Connecting to HSQLDB
  3. import groovy.sql.Sql

  4. def url = 'jdbc:hsqldb:mem:yourDB'
  5. def user = 'sa'
  6. def password = ''
  7. def driver = 'org.hsqldb.jdbcDriver'
  8. def sql = Sql.newInstance(url, user, password, driver)

  9. // use 'sql' instance ...

  10. sql.close()
  11. If you don’t want to have to handle resource handling yourself (i.e. call close() manually) then you can use the withInstance variation as shown here:

  12. Connecting to HSQLDB (withInstance variation)
  13. Sql.withInstance(url, user, password, driver) { sql ->
  14.   // use 'sql' instance ...
  15. }
复制代码

使用道具

藤椅
ReneeBK 发表于 2017-3-12 10:40:25 |只看作者 |坛友微信交流群
  1. Connecting with a DataSource

  2. It is often preferred to use a DataSource. You may have one available to you from a connection pool. Here we’ll use the one provided as part of the HSQLDB driver jar as shown here:

  3. Connecting to HSQLDB with a DataSource
  4. import groovy.sql.Sql
  5. import org.hsqldb.jdbc.JDBCDataSource

  6. def dataSource = new JDBCDataSource(
  7.     database: 'jdbc:hsqldb:mem:yourDB', user: 'sa', password: '')
  8. def sql = new Sql(dataSource)

  9. // use then close 'sql' instance ...
  10. If you have your own connection pooling, the details will be different, e.g. for Apache Commons DBCP:

  11. Connecting to HSQLDB with a DataSource using Apache Commons DBCP
  12. @Grab('commons-dbcp:commons-dbcp:1.4')
  13. import groovy.sql.Sql
  14. import org.apache.commons.dbcp.BasicDataSource

  15. def ds = new BasicDataSource(driverClassName: "org.hsqldb.jdbcDriver",
  16.     url: 'jdbc:hsqldb:mem:yourDB', username: 'sa', password: '')
  17. def sql = new Sql(ds)
  18. // use then close 'sql' instance ...
复制代码

使用道具

板凳
auirzxp 学生认证  发表于 2017-3-12 10:40:42 |只看作者 |坛友微信交流群

使用道具

报纸
ReneeBK 发表于 2017-3-12 10:41:57 |只看作者 |坛友微信交流群
  1. Connecting using @Grab

  2. For a self-contained script you can add @Grab statements to the top of the script to automatically download the necessary jar as shown here:

  3. Connecting to HSQLDB using @Grab
  4. @Grab('org.hsqldb:hsqldb:2.3.2')
  5. @GrabConfig(systemClassLoader=true)
  6. // create, use, and then close sql instance ...
  7. The @GrabConfig statement is necessary to make sure the system classloader is used. This ensures that the driver classes and system classes like java.sql.DriverManager are in the same classloader.
复制代码

使用道具

地板
franky_sas 发表于 2017-3-13 17:57:28 |只看作者 |坛友微信交流群

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-10-6 23:28