public examination[] sortAll2()throws Exception { String sql="select count(*) from examination where grade <60"; PreparedStatement pre = connect.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//改成可以改位置 ResultSet rs = pre.executeQuery(); rs.last();//光标移到最后 int rowCount=rs.getRow();//当前行是第几行 rs.beforeFirst();//移回去 examination[] examinations=new examination[rowCount]; int i=0; while(rs.next()) { examinations[i]=new examination(); examinations[i].stuid=rs.getString("stuid"); examinations[i].examname=rs.getString("examname"); examinations[i].grade=rs.getInt("grade"); i++; } pre.close(); return examinations; } public examination[] sortAll()throws Exception { String sql="select count(*) from examination where grade >89"; PreparedStatement pre = connect.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//改成可以改位置 ResultSet rs = pre.executeQuery(); rs.last();//光标移到最后 int rowCount=rs.getRow();//当前行是第几行 rs.beforeFirst();//移回去 examination[] examinations=new examination[rowCount]; int i=0; while(rs.next()) { examinations[i]=new examination(); examinations[i].stuid=rs.getString("stuid"); examinations[i].examname=rs.getString("examname"); examinations[i].grade=rs.getInt("grade"); i++; } pre.close(); return examinations; } public examination[] searchAll(String stuid,String examname,String teaid)throws Exception { String sql="select * from examination where stuid like ? and examname like ? and teaid=?"; PreparedStatement pre = connect.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);//改成可以改位置 pre.setString(1,"%"+stuid+"%"); pre.setString(2,"%"+examname+"%"); pre.setString(3,teaid); ResultSet rs = pre.executeQuery(); rs.last();//光标移到最后 int rowCount=rs.getRow();//当前行是第几行 rs.beforeFirst();//移回去 examination[] examinations=new examination[rowCount]; int i=0; while(rs.next()) { examinations[i]=new examination(); examinations[i].stuid=rs.getString("stuid"); examinations[i].examname=rs.getString("examname"); examinations[i].grade=rs.getInt("grade"); i++; } pre.close(); return examinations; } public boolean ModifyTeacher(String teaid,String teaname,String teapwd)throws Exception { String sql="update teacher set teaname=?,teapwd=? where teaid=?"; PreparedStatement pre = connect.prepareStatement(sql); pre.setString(1,teaname); pre.setString(2,teapwd); pre.setString(3,teaid); int count=pre.executeUpdate(); pre.close(); if(count>=1) return true; else return false; } public boolean ModifyGrades(String stuid,int grade)throws Exception { String sql="update examination set grade=? where stuid=?"; PreparedStatement pre = connect.prepareStatement(sql); pre.setInt(1,grade); pre.setString(2,stuid); int count=pre.executeUpdate(); pre.close(); if(count>=1) return true; else return false; }
标签:总结,pre,examinations,String,rs,30,examination,2023.5,stuid From: https://www.cnblogs.com/wllovelmbforever/p/17444588.html