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="注册失败!";
}