# `executeUpdate`: Example
__*executeUpdate*__
```
import java.sql.Connection;
import java.sql.DriverManager;
import ~!@java.sql.Statement@!~;
public class DemoJdbcExecuteUpdate{
    public static void main(String[] args){
        Connection connection = null;
        try{
            connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:4000/test", "root", ""
            );
            Statement statement = ~!@connection.createStatement()@!~;
            statement.~!@executeUpdate@!~("DROP TABLE IF EXISTS t1");
            statement.~!@executeUpdate@!~("CREATE TABLE t1 (id int PRIMARY KEY, name char(4))");
            int rowCount = 0;
            rowCount = statement.~!@executeUpdate@!~("INSERT INTO t1 VALUES(1, 'ABCD')");
            rowCount = statement.~!@executeUpdate@!~("INSERT INTO t1 VALUES(2, 'EFGH')");
            rowCount = statement.~!@executeUpdate@!~("INSERT INTO t1 VALUES(3, 'IJKL')");
            statement.close();
        }
```

------------------------------------------------------------
The code example in the slide creates and populates a table called t1.

You can tell that the program closes the Statement object. It is good practice to close Statement and ResultSet objects when you are finished with them. Although closing the Connection object and garbage collection normally cleans up unused objects, when you use connection pooling and execute Connection.close(), the Connection object is returned to the pool, but child objects might remain open and potentially cause memory leaks.


Class demo scripts:

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

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

```
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DemoJdbcExecuteUpdate{
    public static void main(String[] args){
        Connection connection = null;
        try{
            connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:4000/test", "root", ""
            );
            Statement statement = connection.createStatement();
            statement.executeUpdate("DROP TABLE IF EXISTS t1");
            statement.executeUpdate("CREATE TABLE t1 (id int PRIMARY KEY, name char(4))");
            int rowCount = 0;
            rowCount = statement.executeUpdate("INSERT INTO t1 VALUES(1, 'ABCD')");
            rowCount = statement.executeUpdate("INSERT INTO t1 VALUES(2, 'EFGH')");
            rowCount = statement.executeUpdate("INSERT INTO t1 VALUES(3, 'IJKL')");
            statement.close();
        }
```
