Forum Discussion
i have changed the code as mentioned below
import groovy.sql.Sql
// 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"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
def conn = sql.getConnection()
try {
def stmt = conn.createStatement()
// Retrieve database names and IDs
def dbRs = stmt.executeQuery("select name, dbid from sysdatabases")
while (dbRs.next()) {
def dbName = dbRs.getString("name")
def dbId = dbRs.getInt("dbid")
// Retrieve segment information for each database
def segmentRs = stmt.executeQuery("select name from '${dbName}'..syssegments where dbid = ${dbId}")
while (segmentRs.next()) {
def segmentName = segmentRs.getString("name")
// Process segment information and create instance
def instanceName = "${dbName}_${segmentName}_segment"
def instanceConfig = [segment: segmentName]
createInstance(instanceName, instanceConfig)
}
segmentRs.close()
}
dbRs.close()
stmt.close()
} catch (e) {
// Handle SQL exception
e.printStackTrace()
} finally {
if (conn != null) {
conn.close()
}
}
def createInstance(name, config) {
def description = config.description
def prop1 = config.prop1
def prop2 = config.prop2
println("${name}##${name}##${description}####prop1name=${prop1}&prop2name=${prop2}")
}
i am getting the following output
Related Content
- 2 years ago
- 3 days ago
- 2 years ago