Here you can find the source of getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName)
Parameter | Description |
---|---|
t | the top SQL Exception (may be <code>null</code>) |
includeExceptionName | if <code>true</code>, the exception name will prefix all messages |
public static String[] getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName)
//package com.java2s; /*/* w w w . j a v a 2s . com*/ * RHQ Management Platform * Copyright (C) 2005-2008 Red Hat, Inc. * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, as * published by the Free Software Foundation, and/or the GNU Lesser * General Public License, version 2.1, also as published by the Free * Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License and the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU General Public License * and the GNU Lesser General Public License along with this program; * if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.sql.SQLException; import java.util.ArrayList; public class Main { /** * Returns all the messages for the SQL Exception and all of its causes. * * @param t the top SQL Exception (may be <code>null</code>) * @param includeExceptionName if <code>true</code>, the exception name will prefix all messages * * @return strings containing the SQL Exception's message and its next exception's messages in order */ public static String[] getAllSqlExceptionMessagesArray(SQLException t, boolean includeExceptionName) { ArrayList<String> list = new ArrayList<String>(); if (t != null) { String tMessage = t.getMessage(); if (includeExceptionName) { list.add(t.getClass().getName() + ":" + tMessage); } else { list.add((tMessage != null) ? tMessage : t.getClass() .getName()); } while ((t.getNextException() != null) && (t != t.getNextException())) { String msg; t = t.getNextException(); tMessage = t.getMessage(); if (includeExceptionName) { msg = t.getClass().getName() + ":" + tMessage; } else { msg = (tMessage != null) ? tMessage : t.getClass() .getName(); } list.add(msg + "(error-code=" + t.getErrorCode() + ",sql-state=" + t.getSQLState() + ")"); } } return list.toArray(new String[list.size()]); } /** * Same as {@link #getAllSqlExceptionMessagesArray(SQLException, boolean)} with the "include exception name" * parameter set to <code>true</code>. * * @param t the top sql exception (may be <code>null</code>) * * @return strings containing the SQL Exception's message and its next exception's messages in order */ public static String[] getAllSqlExceptionMessagesArray(SQLException t) { return getAllSqlExceptionMessagesArray(t, true); } }