import java.sql.*;
class xuexi
{
public static void main(String[]args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:sky";
Connection con=DriverManager.getConnection(url);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("delete from a where class='5'");
s.close();
rs.close();
s=con.createStatement();
rs=s.executeQuery("delete from b where name='aa'");
rs=s.executeQuery("delete from a where class='s203'");
}catch(ClassNotFoundException e)
{
System.out.println(e);
}catch(SQLException e)
{
System.out.println(e);
}
}
}
为什么这两个语句只执行完第一个后,第二个就不执行了呢??如果想让它执行完第一个后继续执行第二个要怎么修改才可以
(如果有第三个表需要删除的话继续删除下一个),高手帮帮我啊
rs=s.executeQuery("delete from b where name='aa'");
rs=s.executeQuery("delete from a where class='s203'");

解决方案 »

  1.   

    你试试用s.executeUpdate("");语句看看,一般delete等无结果集返回的sql语句用Update效率比较高
      

  2.   

    public ResultSet reset(String sql)
    {
    try{
    Connection con;
    Statement s=con.createStatement();
    ResultSet rs=s.executeQuery(sql);
    return rs;
    }

    }

    catch(Exception e){
    e.printStackTrace();
    }
    return null;
    } public static void main(String[] args){
    DB db=new DB();
    db.reset("delete   from   [a]   where   name='aaa'");
    }
      

  3.   

    你的程序写错了啊!改正结果:
    rs=s.executeQuery("delete   from   b   where   name='aa'"); ==>
    rs=s.executeUpdate("delete   from   b   where   name='aa'");
    rs=s.executeQuery("delete   from   a   where   class='s203'");==>
    rs=s.executeUpdate("delete   from   a   where   class='s203'");这样就行。DELETE,CREATE,UPDATE用executeUpdate操作;
    SELECT用executeQuery操作;
      

  4.   

    你确认没有抛出异常吗?
    }catch(SQLException   e) 

    System.out.println(e);  /// 你的控制台没有任何输出??


      

  5.   

    1楼跟3楼说的对,不过要把rs转换正int型的
    谢谢了
      

  6.   

    executeQuery是用来查询时用的select *