Here you can find the source of formatSQLError(SQLException e)
Parameter | Description |
---|---|
e | - the SQL exception |
public static String formatSQLError(SQLException e)
//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(); } }