1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.jdbc;
  17. import java.sql.SQLException;
  18. import org.springframework.dao.InvalidDataAccessResourceUsageException;
  19. /**
  20. * Exception thrown when SQL specified is invalid. Such exceptions always have
  21. * a java.sql.SQLException root cause.
  22. *
  23. * <p>It would be possible to have subclasses for no such table, no such column etc.
  24. * A custom SQLExceptionTranslator could create such more specific exceptions,
  25. * without affecting code using this class.
  26. *
  27. * @author Rod Johnson
  28. * @version $Id: BadSqlGrammarException.java,v 1.2 2004/03/18 02:46:16 trisberg Exp $
  29. */
  30. public class BadSqlGrammarException extends InvalidDataAccessResourceUsageException {
  31. /** Root cause: underlying JDBC exception. */
  32. private final SQLException ex;
  33. /** The offending SQL. */
  34. private final String sql;
  35. /**
  36. * Constructor for BadSqlGrammarException.
  37. * @param task name of current task (may be null)
  38. * @param sql the offending SQL statement
  39. * @param ex the root cause
  40. */
  41. public BadSqlGrammarException(String task, String sql, SQLException ex) {
  42. super("Bad SQL grammar [" + sql + "]" + (task != null ? " in task '" + task + "'" : ""), ex);
  43. this.ex = ex;
  44. this.sql = sql;
  45. }
  46. /**
  47. * Return the wrapped SQLException.
  48. * @return the wrapped SQLException
  49. */
  50. public SQLException getSQLException() {
  51. return ex;
  52. }
  53. /**
  54. * Return the SQL that caused the problem.
  55. * @return the offdending SQL
  56. */
  57. public String getSql() {
  58. return sql;
  59. }
  60. }