org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 54 in the jsp file: /login.jsp
The method executeUpdate(String) in the type Statement is not applicable for the arguments ()
51:  // 编写查询的SQL语句
52:  sql = "INSERT INTO person (title,author,content) VALUES ('wo','woshi','woshini')" ;
53:  // 查询数据库,此方法返回ResultSet对象
54:  rs = stmt.executeUpdate() ;
55: %>
56:  <table border="1" width="80%">57:  <tr>在jsp和jdbc过程中出现的问题,劳烦帮下忙
是什么意思,这个错误

解决方案 »

  1.   

    Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
    Parameters:
    sql an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
    Returns:
    either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
    Throws:
    SQLException - if a database access error occurs, this method is called on a closed Statement or the given SQL statement produces a ResultSet objectrs = stmt.executeUpdate() ;传入sql作为参数。
      

  2.   

    54: rs = stmt.executeUpdate() ;
    返回对象不是记录集,是受影响的记录数
    int affectedCount=stmt.executeUpdate();
      

  3.   

    stmt.executeUpdate(); 楼主这个返回值为int(影响数据记录个数)。3楼正解。
      

  4.   

    他是对sql语句的执行,为什么返回int类型的啊
      

  5.   

    这个方法stmt.executeUpdate()执行Insert、Delete、Update语句,返回受影响的行数,为int型。
    所以,你要用int接受,同时这个方法需要传入一个String类型的参数,这个参数为SQL语句...如果你是要做查询那么用stmt.executeQuery()执行Select语句,返回ResultSet结果集!
    rs.getInt(1);获取Select语句中的第一列,但必须是int型。如果是Varchar就用rs.getString();
      

  6.   

    更正:如果楼主使用的是Statement 那么使用int count = stmt.executeUpdate(sql)来执行sql语句。
    如果楼至使用的是PreparedStatement 那么可以先使用PreparedStatement ps = conn.prepareStatement(sql),然后再执行 ps.executeUpdate();这里就不需要传入sql了。引用: 他是对sql语句的执行,为什么返回int类型的啊楼主这个你通过查API就知道返回值(是int类型)了。它返回的是影响的结果数。你可以来个通过数知道你的sql语句执行后是否真正的更新了或者插入、删除数据了。
      

  7.   

    51: // 编写查询的SQL语句
    52: sql = "INSERT INTO person (title,author,content) VALUES ('wo','woshi','woshini')" ;
    53: // 查询数据库,此方法返回int类型
    54: int result = stmt.executeUpdate() ;
    55: %>
    56: <table border="1" width="80%">57: <tr>
      

  8.   

    54: rs = stmt.executeUpdate() 传sql语句