美文网首页
jdbc中excute,excuteUpdate,excuteQ

jdbc中excute,excuteUpdate,excuteQ

作者: 豪门百里 | 来源:发表于2016-07-04 14:37 被阅读58次

**executeQuery(String sql) **
执行select语句,它返回的是查询后得到记录集(resultset)。

**executeUpdate(String sql) **
执行update,insert,delete语句,它返回的是语句执行后说影响到的记录条数(int)。对于 CREATE TABLE 或 DROP TABLE 等不操作行的DDL语句,executeUpdate 的返回值总为零。

**execute(String sql) **
执行任何sql语句,也就是前两者之一。返回值是第一个结果的表现形式。当第一个执行结果是查询语句时,返回true,可以通过getResultSet方法获取结果;当第一个执行结果是更新语句或DDL语句时,返回false,可以通过getUpdateCount方法获取更新的记录数量。

// executeQuery()得到结果方法
Result rs = st.executeQuery(sql);

// execute()得到结果方法
st.executeQuery(sql);
Result rs = st.getResultSet();

相关文章

网友评论

      本文标题:jdbc中excute,excuteUpdate,excuteQ

      本文链接:https://www.haomeiwen.com/subject/ezsxjttx.html