Java SQLException to String toString(SQLException e)

Here you can find the source of toString(SQLException e)

Description

to String

License

Open Source License

Declaration

public static String toString(SQLException e) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * (c) Copyright 2017 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at/*from   w ww.ja v  a  2s.  c om*/
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *******************************************************************************/

import java.io.*;
import java.sql.SQLException;

public class Main {
    public static String toString(SQLException e) {
        String curr = exceptionToString(e) + "\nstate:" + e.getSQLState();
        while ((e = e.getNextException()) != null)
            curr += "\n\n" + exceptionToString(e) + "\nstate:" + e.getSQLState();
        return curr;
    }

    public static String exceptionToString(Throwable e) {
        // Print the stack trace into an in memory string
        StringWriter writer = new StringWriter();
        e.printStackTrace(new java.io.PrintWriter(writer));

        // Process the stack trace, remove the FIRST null character
        return writer.toString().replace("" + (char) 0x00, "");
    }
}

Related

  1. toString(Throwable x)