(1)boolean execute([sql])
(2)ResultSet executeQuery([sql])
(3)int executeUpdate([sql]) 
java.sql.Statement类中的这三个方法有什么区别吗?实际应用中应该做什么样的选择呢?
String sql="create table t1(id number)";
boolean flag=stm.execute(sql);
结果flag为false
第一个execute返回的是boolean,什么情况下返回false,什么情况下返回TRUE呢?

解决方案 »

  1.   

    不成功时返回false
    第二个看返回类型就可以知道主要在select时候用
    第三个也挺清楚的
      

  2.   

    不是的,当我建表成功后也是返回false哦
      

  3.   

    对不起我瞎说了
    execute有ResultSet 返回则true,没有才是false
    建表因为没有ResultSet 所以false
      

  4.   

    true if the first result is a ResultSet object; false if it is an update count or there are no results 
      

  5.   

    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. 
    executeUpdate一般用来INSERT, UPDATE, or DELETE Executes the given SQL statement, which returns a single ResultSet object. 
    executeQuery一般用来查询
      

  6.   

    如果其为更新计数或者不存在任何结果,则返回 false 
      

  7.   

    execute有ResultSet 返回true, 否者false
      

  8.   

    看一下 API 有详细介绍 
      

  9.   

    后面两个是分别针对DML和DQL语句的
    boolean execute([sql])这个如果执行的是DML,则返回true,可以通过getResultSet来获得结果集如果执行的是DQL,则返回false,可以通过getUpdateCount返回影响行数PS。后面两个方法名我可能记错了