# SQLException: Example

__*SQLException*__
__*SQLSTATE*__
__*ErrorCode*__

```
private void doSomething() {
  try {
    ...
  }
  catch(SQLException e) {
    System.out.println("SQL Exception code:!" + e.~!@getErrorCode()@!~);
    System.out.println("SQL Exception state: " + e.~!@getSQLState()@!~);
    System.out.println("SQL Exception text: " + e.~!@getMessage()@!~);
  }
}
```
------------------------------------------------------------------------
`SQLSTATE` 是 SQL 规范,错误代码由 MySQL 定义,也由 TiDB 实现。

试着修改一下以下脚本指向的 Java 类, 使其出错, 观察输出。

```
Class demo scripts:

For MacOS and Linux: https://github.com/pingcap/tidb-course-201-lab/blob/master/scripts/09-demo-jdbc-execute-update-tx-01-show.sh

For Windows: https://github.com/pingcap/tidb-course-201-lab/blob/master/scripts/09-demo-jdbc-execute-update-tx-01-show.bat
```