int无法转换为结果集

时间:2016-01-01 14:56:21

标签: java swing

当我使用executeQuery()java.sql.SQLException时,我得到:Can not issue data manipulation statements with executeQuery()

public boolean newStudent(String sname,String gender,
                        String level,String faculty,
                        String section,String address,
                        String contactNo,String comment)
    {
        try{
            std.setString(1,sname);
            std.setString(2,gender);
            std.setString(3,level);
            std.setString(4,faculty);
            std.setString(5,section);
            std.setString(6,address);
            std.setString(7,contactNo);
            std.setString(8,comment);
            stdRes=std.executeUpdate();
            if(res.next()){
                System.out.println("Succesfully saved!");
                return true;
            }else{
                System.out.println("Data save process interrupted");
                return false;
            }

        }catch(Exception e){
            System.out.println(e);
            //e.printStackTrace();
            return false;
        }
    }

1 个答案:

答案 0 :(得分:2)

从您的代码中,似乎有问题的行

stdRes = std.executeUpdate();

.executeUpdate()返回int。因此,请确保将结果分配给int变量:

int result = std.executeUpdate();