public int[] updates(int[] nums) throws SQLException, ClassNotFoundException{
link();
String sql="update grade set gradeid=gradeid+1 where gradeid=?";
pstmt=con.prepareStatement(sql);
for (int i = 0; i < nums.length; i++) {
pstmt.setInt(1,nums[i]);
pstmt.addBatch();
}
int[] num=pstmt.executeBatch();
close();
return num;

}
public static void main(String[] args) throws ClassNotFoundException, SQLException {
int[] nums={93,21};
StusDao sd=new StusDao();
int[] num=sd.updates(nums);
System.out.println(num);
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}

}JDBC

解决方案 »

  1.   

    你的sql语句写错了啊  ,String sql="update grade set gradeid=gradeid+1 where gradeid=?";
    这个根本就没有执行
      

  2.   

    int[] num=pstmt.executeBatch();
    这句就是执行SQL语句的啊
    我这句在pl/sql里可以执行,应该没问题吧
      

  3.   

    楼主你先检查下你connection的autoCommit是否是false,如果是false,增删改的语句不进行conn.commit()是不会提交到数据库的
      

  4.   

    加了commit()还是不行,之前不用批处理执行还有效的,我再研究研究,谢谢你啦
      

  5.   

    你执行之前有没有建立数据库连接的?????这个link();是建立连接的?????
      

  6.   

    是的,link()是我自己写的一个方法