![](/img/trans.png)
[英]Is there a way to programatically pull the sprint number from JIRA from CLI or Groovy?
[英]Pull Syslog from the server using Groovy in Jira
我是Jira的Groovy的新手,并且正在尝试从某个数据库中提取系统日志。 我想知道是否有人可以向正确的方向发展。 我正在使用脚本控制台来实现这一点。
我猜它将在本地主机上。 我得到这些访问数据库服务器:
-具有端口号的数据库服务器
-数据库名称
-密码
-应用程序数据库用户
-Syslog服务器
我可以使用任何教程来连接数据库服务器吗?
非常感谢你,
Groovy提供了Sql类来简化与JDBC数据源的连接。 这是一个例子。
import groovy.sql.Sql
def jdbc = 'jdbc:h2:mem:'
def db = Sql.newInstance(jdbc, 'org.h2.Driver')
def foos = db.rows('select foo from bar')
...
db.close() // Done with connection
驱动程序和JDBC连接字符串取决于您要连接的DBMS(MySQL,PostgreSQL等)。
这是连接到PostgreSQL的方法。 下面的代码使用Groovy的Grape下载依赖。
注意:需要@GrabConfig
以允许jdbc找到它的方式加载org.postgresql.Driver
类。
@Grab('org.postgresql:postgresql:9.3-1101-jdbc41')
@GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
def host = '192.168.1.1'
def port = 5432
def dbname = 'foo'
def user = 'xxx'
def password = 'yyy'
def jdbc = "jdbc:postgresql://${host}:${port}/${dbname}"
def db = Sql.newInstance(jdbc, user, password, 'org.postgresql.Driver')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.