Forum Discussion
import groovy.sql.Sql
//@Grab('org.hsqldb:hsqldb:2.7.1:jdk8')
//@GrabConfig(systemClassLoader=true)
Class.forName("com.sybase.jdbc4.jdbc.SybDriver")
// Get basic info to connect
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
// Construct an SQL instance with a url and a driver
def url = "jdbc:sybase:Tds:${hostname}:${port}", username=user, password=pass
// Sybase SQL Driver
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
// Create a connection to the SQL server
def sql = Sql.newInstance(url, user, pass, driver)
def results = []
sql.withTransaction {
// Iterate over query results and list the databases
def wildvalue = instanceProps.get("wildvalue")
results = sql.rows("select spid, blocked from master..sysprocesses WHERE db_name(dbid)=${wildvalue}")
}
sql.close()
// Format the results as key-value pairs
def resultParsed = results.collect { row ->
"SPID = ${row.spid}\nBLOCKED = ${row.blocked}\n"
}
// Join the results with newlines and print the output
println resultParsed.join("\n")
return 0
Related Content
- 2 years ago
- 3 days ago
- 2 years ago