Reading custom data sources error Messages
Hi please find the below code
import groovy.sql.Sql
import java.sql.SQLException
// Register the Sybase driver
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
def wildvalue = instanceProps.get("wildvalue")
def url = "jdbc:sybase:Tds:" + hostname + ":21000"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
// Check Sybase server status
try {
sql.getConnection()
println("status:0") // Server is online
} catch (SQLException e) {
if (e.getMessage().contains("Login failed")) {
println("status:1") // Invalid password or login failed
} else {
println("status:2") // Other connection or server error, including server offline
}
} finally {
sql.close()
}
when i run this code . iam getting status 0 as my output. i want to test how this script works for login failed. i have tried this code with wrong credentials then it is not printing any thing its showing error message
code:
The script failed, elapsed time: 0 seconds - JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason(s).java.sql.SQLException: JZ00L: Login failed. Examine the SQLWarnings chained to this exception for the reason(s). at com.sybase.jdbc4.jdbc.ErrorMessage.raiseError(ErrorMessage.java:775) at com.sybase.jdbc4.tds.Tds.processLoginAckToken(Tds.java:5382) at com.sybase.jdbc4.tds.Tds.doLogin(Tds.java:725) at com.sybase.jdbc4.tds.Tds.login(Tds.java:579) at com.sybase.jdbc4.jdbc.SybConnection.tryLogin(SybConnection.java:422) at com.sybase.jdbc4.jdbc.SybConnection.handleHAFailover(SybConnection.java:3335) at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:348) at com.sybase.jdbc4.jdbc.SybConnection.<init>(SybConnection.java:253) at com.sybase.jdbc4.jdbc.SybDriver.connect(SybDriver.java:232) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677) at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228) at groovy.sql.Sql.newInstance(Sql.java:422) at groovy.sql.Sql.newInstance(Sql.java:466) at groovy.sql.Sql$newInstance.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:152) at Script272.run(Script272.groovy:16)
so please help to how to avoid the error mesage and print status 2