Statement statement = conn.createStatement();
ResultSet rs1 = statement.executeQuery(
"Select count(*) from user where username=? OR email=? OR phone=?"
);
int c = 0;
while (rs1.next()) {
c++;
}
答案 0 :(得分:3)
您的代码有一些问题:
PreparedStatement
,因为您使用的是?
占位符相反,您的代码应如下所示:
String query= "Select count(*) as cnt from user where username=? OR email=? OR phone=?";
try (PreparedStatement pstmt = conn.prepareStatement(query);) {
pstmt.setString(1, username);
pstmt.setString(2, email);
pstmt.setString(3, phone);
ResultSet rs1 = pstmt.executeQuery();
long c = 0;
if(rs1.next()){
c = rs1.getLong("cnt");
}
}