poojavb 29 Junior Poster

Hello,

I need to populate my ComboBox in VB.Net using MySQL.

Can anyone help me to start.

I have created a combo box which should contain the patient name from the database.
I am using MySQL database.

Please help me in this.

Regards,
Pooja

poojavb 29 Junior Poster

Updating the value of what? A JTextField? A JLabel?
Put (the proper) listener on whatever item is being changed,
to go and update the item on the other tab page.

In the next Tab I am having a JTable.
The values in the JTable are fetched from the database.
The database is getting updated correctly when the value is changed in the earlier tab but not getting reflected in the JTable at the very first time.
I need to refresh the page when I click on the second tab.

How should I do this?
I had added the listener also to the JTabbedPane.

poojavb 29 Junior Poster

Hello All,

I am stuck in one issue.

When I update a value in one tab of a JTabbedPane, the same value does not get updated in the other tab

I tried using the StateChange event but still did not succeed.

I need to refresh the second tab as soon as any changes are saved in the forst tab.

Please help me in this.

Thanks in advance.
Pooja

poojavb 29 Junior Poster

Can anyone help me in how to clear the editor of combo box?
Not the items present in the combo box but just the editor since I have set the setEditable property of JComboBox to true.

The answer is
combo.getEditor().setItem(null);

poojavb 29 Junior Poster

well,
I am not sure I can help you much with these issues you are having. However, I would like to just give you some feedback which might help you rethink things and perhaps find a solution.

your line fifteen says "do line 17 if there is no more results in rs"

AND, you reset the selected item on line 26 every time there is a result in rs. naturally, this causes the last result on you result set to be selected as the item on cboBreed.

hope this helps a bit.

Can anyone help me in how to clear the editor of combo box?
Not the items present in the combo box but just the editor since I have set the setEditable property of JComboBox to true.

poojavb 29 Junior Poster

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.

poojavb 29 Junior Poster

try this:

"select BreedName from breedmaster where BreedName like(%"+ch+"%)";

this could be one problem. hope this works, if it does not, let us know what exactly is happening so that we can help you more.

I have written the following code

cboBreed.getEditor().getEditorComponent().addKeyListener(new java.awt.event.KeyListener(){
	public void keyTyped(java.awt.event.KeyEvent kevt) 
	{
		try
		{
			char ch=kevt.getKeyChar();	
			con=ConnectionPooling.getConnection();
			Statement stmtBreed=con.createStatement();
			ResultSet rs=null;
			String getspec=cboSpecies.getSelectedItem().toString();
			String ss="select BreedName from breedmaster where SpeciesName='"+getspec+"' and BreedName like '"+ch+'%'+"'";
			rs=stmtBreed.executeQuery(ss); 
			if(rs!=null)
			{
				if (!rs.next()) 
				{ 
					JOptionPane.showMessageDialog(null, "<html><p><font color=\"#FF8C00\" " +
							"size=\"4\" face=\"Book Antiqua\">Select correct breed name"+
							"</font></p></html>" ,"Error:",JOptionPane.ERROR_MESSAGE);
				} 
				else
				{     
					do 
					{     									
						String name=rs.getString(1);
						cboBreed.setSelectedItem(name);
					}while(rs.next());
				}
			}
			con.close();
		}
		catch(SQLException excpt)
		{
			excpt.printStackTrace();
		}
	}
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){}
});

The query is working fine but I am facing the following issues
1. Whenever I type a character, even that character comes in the editor of the drop down of breed at the end along with the breed name eg. Bulldogb ---- b gets added at the end
2. If there are more than one breed with same starting alphabet the last breed gets selected in the drop down
3. After the user enters any key in the editor of the breed combo box I want the combo box list to be displayed to the user

But I have no ideas as to how to proceed.

Please help me in this.

Thanks,
Pooja

poojavb 29 Junior Poster

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

poojavb 29 Junior Poster

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

poojavb 29 Junior Poster

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
				{ …
poojavb 29 Junior Poster

Thanks for ur reply...

This requirememt is because if the project goes to different clients then it would depend whether that organization requires auto number or not.

Thank u all.
I did the coding and got it correctly.

poojavb 29 Junior Poster

you can do the filtering on the database. this is actually very easy in sql based databases.

perhaps a key up handler should be defined. every time a key is released, the database should be queried for records that contain the string you have in your input field, or whatever it is, and then the query result should populate your combobox.

querying database records that contain a string on a field is as easy as:
SELECT * FROM table WHERE field LIKE(%str%);

the % character is important because based on it the database knows if you are looking for records that start with str, or if it does not matter where str is within the desired queries. just do some searching for 'sql like' and you will be fine.

I have added the following qote but it is not working as expected.

cboBreed.getEditor().getEditorComponent().addKeyListener(new java.awt.event.KeyListener(){
	public void keyTyped(java.awt.event.KeyEvent kevt) 
	{
		System.out.println("Inside Key Listener event");
		try
		{
			System.out.println("Inside the try block");
			char ch=kevt.getKeyChar();	
			System.out.println("Character key typed: "+ch);
			con=ConnectionPooling.getConnection();
			Statement stmtBreed=con.createStatement();
			ResultSet rs=null;
			String ss="select BreedName from breedmaster where BreedName like '"+'%'+ch+'%'+"'";
			rs=stmtBreed.executeQuery(ss); 

			if(rs!=null)
			{
				while(rs.next())
				{
					System.out.println("In the while loop");
					cboBreed.setSelectedItem(String.valueOf(ch));
				}
			}
		}
		catch(SQLException excpt)
		{
			excpt.printStackTrace();
		}
	}
	public void keyPressed(KeyEvent e){}
	public void keyReleased(KeyEvent e){}
});

Please let me know what mistake I am doing.

poojavb 29 Junior Poster

Oh, so, in other words, you are simply going to wait and hope someone does it for you? Find an access forum/documentation/whatever and find out about sequences, then simply slap a letter onto the front of it while padding its length (and the access documentation will also show you how to do that). At least try, then post your attempt and maybe someone will help you fix it, if it doesn't work.

I have written a code in such a way that a numeric string gets incremented.

But I want an alphabet to be at its position and a number should be auto incremented.

Statement stmtUpdate = con.createStatement();
String Patientidval=txtPatientId.getText();
System.out.println("Patient ID value : "+Patientidval);
//s = String.valueOf(Integer.parseInt(s) + 1);
Patientidval=String.valueOf(Integer.parseInt(Patientidval)+1);
int idval=Integer.parseInt(Patientidval);
System.out.println("id value after converting : "+idval);
//idval=idval+1;
System.out.println("id value after adding one : "+idval);
String abc=Integer.toString(idval);
System.out.println("value of abc : "+abc);
String del1="delete from autoidvalue";
stmtUpdate.executeUpdate(del1);
System.out.println("Delete query: "+del1);
String Query="insert into autoidvalue values('"+Patientidval+"')";
System.out.println("Insert query: "+Query);
stmtUpdate.executeUpdate(Query);
System.out.println("Auto ID value: "+abc);
con.close();
poojavb 29 Junior Poster

Hello Friends,

I need a hint to auto complete the combobox.

I have two table SpeciesMaster and BreedMaster (Access Database)

In the java code on the action Listener of the Species combo Box the breed details gets populated in the breed combobox.

But now I want to filter the breed combobox in such a way that if a user presses any character, then all the breed which has that character should get populated in that combo box.

The breed combo box is an editable combo box.

Can anyone help me out in this?

Thanks in advance.

Regards

poojavb 29 Junior Poster

As a Senior Oracle Database Developer, I would NEVER mix datatypes in a single column!
However...
If it is in a standard format (ie. always 6 characters, starting with 2 letters)
New_ID := SubStr (Old_ID, 1, 2) || LPad (To_Char (To_Number (SubStr (Old_ID, 3)) + 1), 4, '0');

The database is an access database.
The coding is done in Java.

poojavb 29 Junior Poster

Hello Friends,

Can anyone tell me how to increment a String variable by 1 in database.

Suppose the database table has value as SL1000 and we want the next value to be SL1001.
What should be done for such type of requirement in java.

poojavb 29 Junior Poster

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

poojavb 29 Junior Poster

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.

poojavb 29 Junior Poster

Sorry, I can't help you there as it is fault of someone who took the requirements that he/she allowed for such nonsense.

Thanks for ur reply...

This requirememt is because if the project goes to different clients then it would depend whether that organization requires auto number or not.

poojavb 29 Junior Poster

This page is working for me.

I tried to view the page in IE8 / win7 and also in FF.
The contents of the page are visible to me.

Please have a look at the attachment

poojavb 29 Junior Poster

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.

poojavb 29 Junior Poster

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...

poojavb 29 Junior Poster

Thanks for the quick reply, but the actual scenario is as below:

Actually we have an application in such a way that it depends on the user if he wants to have an autonumber for id or not.

If the autonumber radiobutton is enabled then it will take the value from the table where the value is stored.

If the autonumber radiobutton is disabled then the user will be able to enter any id in the front end.

poojavb 29 Junior Poster

Hello All,

I need to create a java code for auto numbering.

A value will be mentioned in a table in database eg 10000.

The java file has to retrive the database value and start the auto numbering from that particular number.

It should increment by 1 for the next data as soon as we click on Save button.

I am not able to get any hint as to how to start.

Could anyone please help me in this?

Thanks in Advance.
Pooja