protected int getCount(String constraint) {
		int res = -1;
		
		String sql = "SELECT COUNT(*) FROM " + TableName;
		if (constraint != null && constraint.length() > 0) sql += " WHERE " + constraint;
		
		log.finest(sql);
		ResultSet rs = null;
		Statement stat = null;
		try {
			stat = DatabaseConnection.getInstance().getConnection().createStatement();
			rs = stat.executeQuery(sql);
			if(rs.next()) {
				res = rs.getInt(1);
			}
		} catch (SQLException e) {
			log.log(Level.SEVERE, "getCount failed: " + e.getMessage(), e);
		} finally {
			try {
				if (rs != null) rs.close();
				if (stat != null) stat.close();
			} catch (SQLException es) {
				log.log(Level.WARNING, "failed to close database resources: " + es.getMessage(), es);
			}
		}
		
		return res;
	}