//ResultSet rs=db.executeQuery(sql);插入不应该返回resultset

解决方案 »

  1.   

    但是我的sql 语句如何执行,要调用executeQuery(sql)在能执行语句.
      

  2.   

    ResultSet rs=db.executeQuery(sql);应该改成db.executeUpdate(sql);executeUpdate
    public int executeUpdate(String sql)
                      throws SQLException
    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 INSERT, UPDATE or DELETE statement or an SQL statement that returns nothing 
    Returns:
    either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing 
    Throws: 
    SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object
      

  3.   

    sorry,我没仔细看你的bean,实际上你的bean里应该有这样一个方法:  public int executeUpdate(String sql) {
        rs = null;
        int num=0;
        try {
          conn = DriverManager.getConnection(sConnStr, "Julianne", "237726");
          Statement stmt = conn.createStatement();
          num = stmt.executUpdate(sql);
        }
        catch (SQLException ex) {
          System.err.println("sqlException" + ex.getMessage());
        }
        return num;
      }
      

  4.   

    xunyiren: 你说的第一种方法"throw"我也看过但是没有弄明白,第二种方法"num=stmt.executUpdate(sql)"的类型不匹配.能否将第一种方法讲详细点?
      

  5.   

    stmt.executUpdate(sql)<----------------????
    拼写错误  ↑ 'e' expeced执行非SELECT语句时是不返回ResultSet的。如果操作所影响的行数不是必要数据,就没必要取出来再付给某个变量了。