Java SQL Date Format formatSQLError(SQLException e)

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

Description

Formats the specified the SQL exception object displaying the error message, error code and the SQL state code.

License

Open Source License

Parameter

Parameter Description
e - the SQL exception

Declaration

public static String formatSQLError(SQLException e) 

Method Source Code

//package com.java2s;
/*// w  ww.  j  a v  a  2s . c o  m
 * MiscUtils.java
 *
 * Copyright (C) 2002-2015 Takis Diakoumis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 *
 * 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 for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.sql.SQLException;

public class Main {
    /**
     * Formats the specified the SQL exception object
     * displaying the error message, error code and
     * the SQL state code.
     *
     * @param e - the SQL exception
     */
    public static String formatSQLError(SQLException e) {
        if (e == null) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        sb.append(e.getMessage());
        sb.append("\nError Code: " + e.getErrorCode());

        String state = e.getSQLState();
        if (state != null) {
            sb.append("\nSQL State Code: " + state);
        }
        sb.append("\n");
        return sb.toString();
    }
}

Related

  1. formatDateToCustfmt(java.util.Date date, String dateFmt)
  2. formatDurationMillisToString(long millis)
  3. formatFloat(int floatValue)
  4. formatLogParam(Array obj)
  5. formatNumberWithZeroPrefix(int numOfZero, Integer value)
  6. formatSqlException( StringBuilder errorMessage, SQLException exception)
  7. formatSQLForColumnName(Connection conn, String strSQL)