Code example for ResultSet

Methods: getRow, last

0
	 
	static public boolean isValidUser(String username) throws SQLException {
		String sql = "SELECT id, username FROM tb_user WHERE tb_user.barcode = '" + username + "'";
		MySQL db = new MySQL();
		ResultSet rs = db.ReturnQuery(sql);
		rs.last();
		int row = rs.getRow();	
		db.Close();
		return row == 1;
	} 
	 
	static public User getUserByName(String username) throws SQLException {
		String sql = "SELECT id, username FROM tb_user WHERE tb_user.barcode = '" + username + "'";
		MySQL db = new MySQL();
		ResultSet rs = db.ReturnQuery(sql);
		while (rs.next()) {
			int id = rs.getInt(1);
			String user = rs.getString(2);
			db.Close();
			return new User(user, id);
		}