Java SQLWarning to String toString(SQLWarning sqlw)

Here you can find the source of toString(SQLWarning sqlw)

Description

Convert the given SQLWarning into a String.

License

Open Source License

Parameter

Parameter Description
sqlw The SQLWarning

Declaration


public static String toString(SQLWarning sqlw) 

Method Source Code

//package com.java2s;

import java.sql.SQLWarning;
import java.sql.SQLException;

public class Main {
    /** Convert the given SQLWarning into a String.
        /*from  w ww  .  j av a2  s .  c  o  m*/
    @param sqlw The SQLWarning
    */

    public static String toString(SQLWarning sqlw) {
        StringBuffer buffer = new StringBuffer();
        String newLine = System.getProperty("line.separator");
        do {
            buffer.append("error code = ").append(sqlw.getErrorCode()).append(newLine);
            buffer.append("localized message = ").append(sqlw.getLocalizedMessage()).append(newLine);
            buffer.append("message = ").append(sqlw.getMessage()).append(newLine);
            buffer.append("sqlstate = ").append(sqlw.getSQLState()).append(newLine);
            sqlw = sqlw.getNextWarning();
        } while (sqlw != null);

        return buffer.toString();
    }

    /** Convert the given SQLException into a String.
        
    @param sqlx The SQLException
    @return A String
    */

    public static String toString(SQLException sqlx) {
        StringBuffer buffer = new StringBuffer();
        String newLine = System.getProperty("line.separator");
        do {
            buffer.append("error code = ").append(sqlx.getErrorCode()).append(newLine);
            buffer.append("localized message = ").append(sqlx.getLocalizedMessage()).append(newLine);
            buffer.append("message = ").append(sqlx.getMessage()).append(newLine);
            buffer.append("sqlstate = ").append(sqlx.getSQLState()).append(newLine);
            sqlx = sqlx.getNextException();
        } while (sqlx != null);

        return buffer.toString();
    }
}

Related

  1. toString(SQLWarning warnings)