001/* 002 * Copyright 2002-2012 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.InvalidDataAccessResourceUsageException; 022 023/** 024 * Exception thrown when SQL specified is invalid. Such exceptions always have 025 * a {@code java.sql.SQLException} root cause. 026 * 027 * <p>It would be possible to have subclasses for no such table, no such column etc. 028 * A custom SQLExceptionTranslator could create such more specific exceptions, 029 * without affecting code using this class. 030 * 031 * @author Rod Johnson 032 * @see InvalidResultSetAccessException 033 */ 034@SuppressWarnings("serial") 035public class BadSqlGrammarException extends InvalidDataAccessResourceUsageException { 036 037 private String sql; 038 039 040 /** 041 * Constructor for BadSqlGrammarException. 042 * @param task name of current task 043 * @param sql the offending SQL statement 044 * @param ex the root cause 045 */ 046 public BadSqlGrammarException(String task, String sql, SQLException ex) { 047 super(task + "; bad SQL grammar [" + sql + "]", ex); 048 this.sql = sql; 049 } 050 051 052 /** 053 * Return the wrapped SQLException. 054 */ 055 public SQLException getSQLException() { 056 return (SQLException) getCause(); 057 } 058 059 /** 060 * Return the SQL that caused the problem. 061 */ 062 public String getSql() { 063 return this.sql; 064 } 065 066}