executeQuery和executeUpdate之间的区别

executeQuery

Executes the SQL query in this PreparedStatement object and returns the ResultSet object generated by the query.

执行SQL查询,并返回ResultSet对象。


			PreparedStatement ps = conn.prepareStatement("select * from user where user_name=? and user_pwd=?");
			ps.setString(1, username);
			ps.setString(2, password);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				flag=true;
			}



executeUpdate

Executes the SQL statement in this PreparedStatement object, which must be an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.

可执行增,删,改,返回执行受到影响的行数。

用于执行 INSERT、UPDATE 或 DELETE 语句以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。对于 CREATE TABLE 或 DROP TABLE 等不操作行的语句,executeUpdate 的返回值总为零。


			PreparedStatement ps = conn.prepareStatement("insert into User(user_name,user_pwd) values(?,?)");
			ps.setString(1, username);
			ps.setString(2, password);
			int i = ps.executeUpdate();
			if(i>0){
				message="注册成功!";
			}else{
				message="注册失败!";
			}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值