I need a help to understand what condition can be applied to the below requirement:

If suppose we have 2 species name eg. dog and cat...
and we have few breed name for the above mentioned species....

so what condition can be applied in such a way that the user can enter 2 different species with the same breed name....

Please help me in this...

Please note the species and breed names will be dyanamic....no hard coding is done...

Thanks in advance...

If I want to store data in an data base, what I would do is by using species_id and breed_id

# Species
------------------------------------------------------------
species_id	        |	species_name
------------------------------------------------------------
1			|	dog
2			|	cat
------------------------------------------------------------

# Breeds
-------------------------------------------------------------------------------
breed_id	        |	species_id	       |	breed_name
-------------------------------------------------------------------------------
1			|	1			|	Bulldog
2			|	1			|	Boxer
3			|	2			|	Persian
4			|	2			|	Abyssinian
5			|	1			|	Rottweiler
6			|	2			|	Ragdoll
7			|	1			|	CatDoggy ;)
8			|	2			|	CatDoggy ;)
-------------------------------------------------------------------------------

Hope I understood you requirement correctly

If I want to store data in an data base, what I would do is by using species_id and breed_id

# Species
------------------------------------------------------------
species_id	        |	species_name
------------------------------------------------------------
1			|	dog
2			|	cat
------------------------------------------------------------

# Breeds
-------------------------------------------------------------------------------
breed_id	        |	species_id	       |	breed_name
-------------------------------------------------------------------------------
1			|	1			|	Bulldog
2			|	1			|	Boxer
3			|	2			|	Persian
4			|	2			|	Abyssinian
5			|	1			|	Rottweiler
6			|	2			|	Ragdoll
7			|	1			|	CatDoggy ;)
8			|	2			|	CatDoggy ;)
-------------------------------------------------------------------------------

Hope I understood you requirement correctly

Thanks for the reply....

Yes this is what will be in database....

But the user will enter this in frontend.

So I need to know the if condition that would be wriiten in java page so that the requirement is fullfilled.

honestly, I have no idea what exactly you're asking here. why would you mean by
'so what condition can be applied in such a way that the user can enter 2 different species with the same breed name...'
my first answer would be: insert two with the same breed name.

First of all you should provide the user to select for which species that he is going to enter a breed name from a drop down list of existing species.

First of all you should provide the user to select for which species that he is going to enter a breed name from a drop down list of existing species.

I have an interface in which we can add the speciesname from the drop down and the breed name will be entered by user in the text box.

If suppose a species name Dog is present with breed name doberman in the database...
then the user should be able to enter the breed name as doberman again if he selects some other species from the drop down.

I am not able to enter the if condition as how the user will get to enter the different species but same breed.

If suppose a species name Dog is present with breed name doberman in the database...
then the user should be able to enter the breed name as doberman again if he selects some other species from the drop down.

So when saving do a small check

// Inside the Action Listener of Save button
if(!isAvailable(selected_species_id, entered_breed_name))
{
    // Breed name under selected species does not exists
    // So can save the data
}
else
{
    // Breed name under selected species already exists
}

isAvailable method should be something like this

public booloan isAvailable(int speciesId, String newBreedName)
{
	// Query the database with this query
	// "SELECT COUNT(*) AS count FROM Breeds WHERE species_id="+speciesId+" AND breed_name LIKE "+newBreedName+"";

	if(count > 0)
        // count is an int which holds the 'count' value that we are getting from the query
	{
		return true
	}
	return false;
}

So when saving do a small check

// Inside the Action Listener of Save button
if(!isAvailable(selected_species_id, entered_breed_name))
{
    // Breed name under selected species does not exists
    // So can save the data
}
else
{
    // Breed name under selected species already exists
}

isAvailable method should be something like this

public booloan isAvailable(int speciesId, String newBreedName)
{
	// Query the database with this query
	// "SELECT COUNT(*) AS count FROM Breeds WHERE species_id="+speciesId+" AND breed_name LIKE "+newBreedName+"";

	if(count > 0)
        // count is an int which holds the 'count' value that we are getting from the query
	{
		return true
	}
	return false;
}

Ya I will surely try this one...

Thank you

So when saving do a small check

// Inside the Action Listener of Save button
if(!isAvailable(selected_species_id, entered_breed_name))
{
    // Breed name under selected species does not exists
    // So can save the data
}
else
{
    // Breed name under selected species already exists
}

isAvailable method should be something like this

public booloan isAvailable(int speciesId, String newBreedName)
{
	// Query the database with this query
	// "SELECT COUNT(*) AS count FROM Breeds WHERE species_id="+speciesId+" AND breed_name LIKE "+newBreedName+"";

	if(count > 0)
        // count is an int which holds the 'count' value that we are getting from the query
	{
		return true
	}
	return false;
}

For the below code I am getting error as missing return statement }

public boolean isAvailable(String speciesname, String newBreedName)
{
		try
		{
		//connection = new ConnectionPoolingPacs();
		con = connection.getConnection();
		Statement stmt=con.createStatement();
		speciesname =cboSpeciesName.getSelectedItem().toString();
		System.out.println("Selected Species Name: "+speciesname);
		newBreedName=txtBreedName.getText();
		System.out.println("New Breed Name: "+newBreedName);
		// Query the database with this query
		String query1="SELECT COUNT(*) AS count FROM breedmaster WHERE speciesname='"+speciesname+"' AND BreedName LIKE '"+newBreedName+"'";
		ResultSet rs=stmt.executeQuery(query1);
		if (rs!=null)
		{
			while(rs.next())
			{
				int count=rs.getInt(1);
				if(count > 0)
					// count is an int which holds the 'count' value that we are getting from the query
			{
				return true;
			}
			else
			{
				return false;
			}
			}
		}
			
		}
		catch(SQLException sql)
		{
			sql.printStackTrace();
		}
	}

For the below code I am getting error as
cannot find symbol
symbol : variable speciesname
location: class Display.BreedDetails.ButtonListener
if(!isAvailable(speciesname,newBreedName))

if(ID==ID_SAVE)    //save the ipaddress and port,aetitle of local host
				{
					if(RecordFoundupdate)
					{
						if(!isAvailable(speciesname,newBreedName))
						{
								StoreAE=3;
						}
					}
					else
					{
						StoreAE=1;
					}
					////********INTL added new paraMETER hASH TABLE 
					StoreValues();
				}	//if

Please let me know what wrong am I doing?

Thanks in advance.

For the below code I am getting error as missing return statement }

Return false just after the catch statement.

...
      ...
   }
   catch(SQLException sql)
   {
      sql.printStackTrace();
   }
   return false;
}

For the below code I am getting error as
cannot find symbol
symbol : variable speciesname
location: class Display.BreedDetails.ButtonListener
if(!isAvailable(speciesname,newBreedName))

Did you define a variable called speciesname?

Return false just after the catch statement.

...
      ...
   }
   catch(SQLException sql)
   {
      sql.printStackTrace();
   }
   return false;
}

Did you define a variable called speciesname?

Yes I have declared the variable as String for speciesname and also newBreedName

cannot find symbol
symbol : variable speciesname

Above error says you haven't define speciesname variable. Make sure you have define it within the scope

Return false just after the catch statement.

...
      ...
   }
   catch(SQLException sql)
   {
      sql.printStackTrace();
   }
   return false;
}

Did you define a variable called speciesname?

I have defined it in the main class

Where in the main class?? In main method? Does

if(!isAvailable(speciesname,newBreedName))

is also placed in the same scope?

Where in the main class?? In main method? Does

if(!isAvailable(speciesname,newBreedName))

is also placed in the same scope?

My problem is solved. When in other direction.
The code already had a condition to check the breed so I added the && operator and the issue got solved.

Thank you all.

Great..!! :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.