# Prepared Statements And Connector/J: Example

__*useServerPrepStmts*__

+ JDBC parameter: `useServerPrepStmts=true` 
```
// Do something in the connection
String sqlDropTable = "DROP TABLE IF EXISTS test.t1";
String sqlCreateTable = "CREATE TABLE test.t1 (id int primary key, name char(30))";
String sqlInsertIntoTable = "INSERT INTO test.t1 (id, name) VALUES (?, ?)";
~!@PreparedStatement@!~[] pss = new PreparedStatement[]{
    ~!@connection.prepareStatement@!~(sqlDropTable),
    ~!@connection.prepareStatement@!~(sqlCreateTable),
    ~!@connection.prepareStatement@!~(sqlInsertIntoTable)
};
pss[2].setInt(1, 10);
pss[2].setString(2, "ABC");
for (PreparedStatement ps:pss){
    ps.~!@executeUpdate()@!~;
    ps.close();
}
// Finish
```

------------------------------------------------------------

`useServerPrepStmts`: This JDBC parameter must be set to true in order to enable the prepared statement on the server side.

Demo scripts:

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

For Windows: https://github.com/pingcap/tidb-course-201-lab/blob/master/scripts/10-demo-jdbc-prepared-statement-01-show.bat
