Statement对象允许您执行基本的 SQL 查询并通过
        ResultSet类检索结果,这将在后面描述。
      
        要创建一个Statement实例,您可以使用前面描述
      的或
        方法之一对您检索createStatement()到的对象调用该方法
        。ConnectionDriverManager.getConnection()DataSource.getConnection()
        拥有实例后,您可以通过使用要使用的 SQL
      调用方法Statement来执行查询。SELECTexecuteQuery(String)
        要更新数据库中的数据,请使用
        executeUpdate(String SQL)方法。此方法返回与更新语句匹配的行数,而不是被修改的行数。
      
        如果您事先不知道 SQL 语句是 aSELECT还是
        UPDATE/ INSERT,那么您可以使用该execute(String SQL)
        方法。如果 SQL 查询是 , 此方法将返回 true
         SELECT,如果它是
        UPDATE,
        INSERT或
        DELETE语句则返回 false 。如果该语句是一个SELECT查询,您可以通过调用该
        getResultSet()方法来检索结果。如果该语句是UPDATE、
        INSERT或
        语句,您可以通过调用实例
      来
        DELETE检索受影响的行数
        。getUpdateCount()Statement
示例 7.2 Connector/J:使用 java.sql.Statement 执行
          SELECT查询
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
// assume that conn is an already created JDBC connection (see previous examples)
Statement stmt = null;
ResultSet rs = null;
try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery("SELECT foo FROM bar");
    // or alternatively, if you don't know ahead of time that
    // the query will be a SELECT...
    if (stmt.execute("SELECT foo FROM bar")) {
        rs = stmt.getResultSet();
    }
    // Now do something with the ResultSet ....
}
catch (SQLException ex){
    // handle any errors
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());
}
finally {
    // it is a good idea to release
    // resources in a finally{} block
    // in reverse-order of their creation
    // if they are no-longer needed
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException sqlEx) { } // ignore
        rs = null;
    }
    if (stmt != null) {
        try {
            stmt.close();
        } catch (SQLException sqlEx) { } // ignore
        stmt = null;
    }
}