既然是update怎么可能返回记录集rs1

解决方案 »

  1.   

    代码贴出来,没看到声明ResultSet呀?
      

  2.   

    stmt = conn.createStatement();
    stmt.executeUpdate(sql);
      

  3.   

    //executeQuery(sql):用于查询(select)
    //executeUpdate(sql);用于更新(update,insert,delete)
      

  4.   

    直接shen.executeQuery(exp2);就行了
    或者接受返回的一个INT型的值,表明UPDATE了多少条数据。
      

  5.   

    hehe 
    没注意,丢人丢人。
    update 返回是int型的。
      

  6.   

    也报错,我找到原因了,我的shen=con.createStatement(conrs.TYPE_SCROLL_INSENSITIVE,conrs.CONCUR_READ_ONLY);
    定义的是read可是现在在外面手头没资料,忘了可更新连接的参数了那位大瞎帮忙给查一下,谢谢
      

  7.   

    看一下Interface Statement中的方法吧,讲的很清楚。
    public ResultSet executeQuery(String sql)
                           throws SQLException
    Executes the given SQL statement, which returns a single ResultSet object.Parameters:sql - an SQL statement to be sent to the database, typically a static SQL SELECT statementReturns:a ResultSet object that contains the data produced by the given query; never null
    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 nothingReturns:either the row count for INSERT, UPDATE or DELETE statements, or 0 for SQL statements that return nothing
      

  8.   

    try{
      exp2="update students set pwd='"+newpwd+"' where studentid='"+studentid+"'";
      rs1 = shen.executeQuery(exp2);//here 改成shen.executeUpdate(exp2);
    }
    catch(Exception e){
        out.println("error:"+e);  
    }
      

  9.   

    ResultSet conrs = null;
    Connection con = null;
    Statement shen = null;
    con= tjwy.getConnection();  //tjwy为一个连接数据库的been,肯定没问题
    shen=con.createStatement(conrs.TYPE_SCROLL_INSENSITIVE,conrs.CONCUR_READ_ONLY);
    try{
      exp2="update students set pwd='"+newpwd+"' where studentid='"+studentid+"'";
      shen.executeQuery(exp2);
    }
    catch(Exception e){
        out.println("error:"+e);  
    }
    以上语句还是有问题,我觉得就是shen = con.createStatement(.....,...._READ_ONLY)这句有问题那位老兄帮忙给查一下,拜托...
      

  10.   

    createStatement
    public Statement createStatement(int resultSetType,
                                     int resultSetConcurrency)
                              throws SQLException
    Creates a Statement object that will generate ResultSet objects with the given type and concurrency. This method is the same as the createStatement method above, but it allows the default result set type and concurrency to be overridden. Parameters:
    resultSetType - a result set type; one of ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE, or ResultSet.TYPE_SCROLL_SENSITIVE
    resultSetConcurrency - a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE 
    Returns:
    a new Statement object that will generate ResultSet objects with the given type and concurrency 
    Throws: 
    SQLException - if a database access error occurs or the given parameters are not ResultSet constants indicating type and concurrency
    Since: 
    1.2 是不是这个?
      

  11.   

    rs1 = shen.executeQuery(exp2);
    应该改为:rs1=shen.executeUpdate(exp2);