int i=stmt.executeUpdate(sql);
i就是影响的行数

解决方案 »

  1.   

    可是int i=stmt.executeUpdate("select * ...."); 会抛出异常
      

  2.   

    要用try()catch(SQLException e)来捕获
      

  3.   

    stmt.executeUpdate不能用于select
    只能使用于insert,update
      

  4.   

    如果你要得到查询的记录数可以用:
    记录数
    ResulteSet resultSet=stmt.executeQuery("select count(*) from my_table");
    resultSet.next();
    int rowcount=resultSet.getInt(1);
      

  5.   

    executeUpdate
    public int executeUpdate()
                      throws SQLException
    Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement. Returns:
    either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing 
    Throws: 
    SQLException - if a database access error occurs or the SQL statement returns a ResultSet object