001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jdbc; 018 019import java.sql.SQLException; 020 021import org.springframework.dao.UncategorizedDataAccessException; 022import org.springframework.lang.Nullable; 023 024/** 025 * Exception thrown when we can't classify an SQLException into 026 * one of our generic data access exceptions. 027 * 028 * @author Rod Johnson 029 * @author Juergen Hoeller 030 */ 031@SuppressWarnings("serial") 032public class UncategorizedSQLException extends UncategorizedDataAccessException { 033 034 /** SQL that led to the problem. */ 035 @Nullable 036 private final String sql; 037 038 039 /** 040 * Constructor for UncategorizedSQLException. 041 * @param task name of current task 042 * @param sql the offending SQL statement 043 * @param ex the root cause 044 */ 045 public UncategorizedSQLException(String task, @Nullable String sql, SQLException ex) { 046 super(task + "; uncategorized SQLException" + (sql != null ? " for SQL [" + sql + "]" : "") + 047 "; SQL state [" + ex.getSQLState() + "]; error code [" + ex.getErrorCode() + "]; " + 048 ex.getMessage(), ex); 049 this.sql = sql; 050 } 051 052 053 /** 054 * Return the underlying SQLException. 055 */ 056 public SQLException getSQLException() { 057 return (SQLException) getCause(); 058 } 059 060 /** 061 * Return the SQL that led to the problem (if known). 062 */ 063 @Nullable 064 public String getSql() { 065 return this.sql; 066 } 067 068}