代码实现
@Override
public int findByUsernameCount(String username) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet res = null;
int count = 0;
conn = JDBCUtils.getConn();
String sql = "select count(*) from tb_card where username=?";
try {
ps = conn.prepareStatement(sql);
ps.setString(1, username);
res = ps.executeQuery();
if (res.next()) {
count = res.getInt(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtils.close(conn, ps, res);
}
return count;
}