The Statement interface provides methods to execute queries with the database.
package com.java.session.ninteen;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class StatementInterfaceExample {
public static void main(String[] args) {
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/emp","root","PASSWORD");
stmt = con.createStatement();
int result = stmt.executeUpdate("delete from emp.employee where id = 11");
System.out.println(result+" records affected");
} catch (ClassNotFoundException ce) {
ce.printStackTrace();
} catch (SQLException se) {
se.printStackTrace();
} finally {
try {
stmt.close();
con.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
}
}