Example usage for java.sql SQLWarning getCause

List of usage examples for java.sql SQLWarning getCause

Introduction

In this page you can find the example usage for java.sql SQLWarning getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:nl.nn.adapterframework.util.JdbcUtil.java

public static XmlBuilder warningsToXmlBuilder(SQLWarning warnings) {
    if (warnings != null) {
        XmlBuilder warningsElem = new XmlBuilder("warnings");
        while (warnings != null) {
            XmlBuilder warningElem = new XmlBuilder("warning");
            warningElem.addAttribute("errorCode", "" + warnings.getErrorCode());
            warningElem.addAttribute("sqlState", "" + warnings.getSQLState());
            String message = warnings.getMessage();

            // getCause() geeft unresolvedCompilationProblem (bij Peter Leeuwenburgh?)
            Throwable cause = warnings.getCause();
            if (cause != null) {
                warningElem.addAttribute("cause", cause.getClass().getName());
                if (message == null) {
                    message = cause.getMessage();
                } else {
                    message = message + ": " + cause.getMessage();
                }/*from ww w.j  a  v  a2 s . c  o m*/
            }

            warningElem.addAttribute("message", message);
            warningsElem.addSubElement(warningElem);
            warnings = warnings.getNextWarning();
        }
        return warningsElem;
    }
    return null;
}

From source file:org.apache.ddlutils.platform.PlatformImplBase.java

/**
 * Logs any warnings associated to the given connection. Note that the connection needs
 * to be open for this.// w  ww .j ava  2 s .co m
 * 
 * @param connection The open connection
 */
protected void logWarnings(Connection connection) throws SQLException {
    SQLWarning warning = connection.getWarnings();

    while (warning != null) {
        getLog().warn(warning.getLocalizedMessage(), warning.getCause());
        warning = warning.getNextWarning();
    }
}