Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in fetching values in combobox from databases.

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,
i m storing date in string format in database, actually i have created three JComboBoxes for Date, month, year.
and i m just appending all the values of all comboboxes before inserting into databases and then inserting into database.
now i need to fetch values from database and display in their combo boxes (i mean: date should be in date combo, month should be in month, so on..)
how can i do this?
although i have not added any delimiter to string, so how do i split the string so i got respective values in respective comboboxes?

 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:hello,
i m storing date in string format in database, actually i have created three JComboBoxes for Date, month, year.
and i m just appending all the values of all comboboxes before inserting into databases and then inserting into database.
now i need to fetch values from database and display in their combo boxes (i mean: date should be in date combo, month should be in month, so on..)
how can i do this?
although i have not added any delimiter to string, so how do i split the string so i got respective values in respective comboboxes?



Hi there.

You could to fetch the value of yours JComboBox and save in a String variable and put a delimiter, like ":"m then, with split function you can separate the values on one array and to put in a JComboBox.

Sorry for my very bad english.

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but how do i add delimiter, i mean where i add delimiter?
i m fetching the whole string from the db, now how do i split that?
i mean this value is coming from db: 12January1981
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there:

That value you can save on a String variable, for the delimiter try this


I hope this can help you.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

private static String INPUT = "12:January:1981"; //Replace here with your JComboBox values


but the value which i am fetching from db has no colon(:) in between.
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:

private static String INPUT = "12:January:1981"; //Replace here with your JComboBox values


but the value which i am fetching from db has no colon(:) in between.


Hi there !!!

Well, you could add the colon at the same time you save the content on your BD table, that is one idea.


 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it helps me, thank you..
i added : to my database also.
but when i m trying to fetch values into my jcombobox.
jcombobox are not changing the values, here is what i am doing:

 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:yes it helps me, thank you..
i added : to my database also.
but when i m trying to fetch values into my jcombobox.
jcombobox are not changing the values, here is what i am doing:



Hi there !!!

This "15", why ??? Replace for a String var. And make sure your variable content it will be equal to "text:text:text"


Something like this:
String var = res.getDay()+ res.getMonth()+res.getYear();

then, you can do
String[] items = p.split(var);
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This "15", why ??? Replace for a String var. And make sure your variable content it will be equal to "text:text:text"


15 is my column number of my database table.


above line shows me the format like this:
1
March
1981

i mean values coming from database in this format:
1:January:1981

now the pattern will covert this in this format:
1
March
1981

now how do i add this to my JComboBox?

table has one column for date.(not different-2 columns for day, month, year).
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!!

Try this:


I'm doing for SWT and it works
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried this:


but my jcombobox are not changing their values..
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String ab = res.getString(15); //What print this line ??? Maybe the problem is right here.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

String ab = res.getString(15); //What print this line ??? Maybe the problem is right here.

1:January:1981
1:January:1981

i dont know why, but it printing date twice.
this is the problem i think??
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!!

Well, you can check if that is the error replacing your res.getString(15); with: "1:January:1981"
But I'm pretty sure that is.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, you can check if that is the error replacing your res.getString(15); with: "1:January:1981"
But I'm pretty sure that is.


changed, but still not working..
part of my code:
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!!

Oks, I'm done on my job, I'll check your code tomorrow when I back.

Regards !!!
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay..
thank you very much Tobias Leon
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!! Let's start.

I tried this part of your code and works for me.


Maybe you should replace the location of that segment, but first, check if you has the same problem with another component, like a JTextField, maybe you should limit your query too, "select * from mitable limit 1"
split.jpg
the split code works for me.
[Thumbnail for split.jpg]
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii, Thank you starting again...
i have replace my location, still nothing is in my comboboxes.
i change component to textfield, and i m getting one date(not twice) in text field.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, i m just trying it and i got something..
actually i m initializing comboboxes with some values like:



it's not working now, i mean combobox values are not changing..
but it i not initialize values, i mean if i do simply like this:


it works, values appears in my combobox, after event happen..
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean values are adding into comboboxes if combox boxes are empty, initially, but if the already have some values the are not changing..
i mean values are adding not changing..
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!!
Then something is wrong with the way you add the values to JCombo, but I can't see any apparent error. I'm working on a Swing solution for this.

Regards !!!
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...
thank you very much...
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!! Sorry for wait so long.




Regards !!!
jcombo.jpg
JComboBox
[Thumbnail for jcombo.jpg]
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii thank you for the reply..
if i initialize comboboxes code will not work..

 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!! Morning !!!

Replace only this part of your code, I add two lines, check it. Now, it works.

Regards !!!
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hii, good evening..
yeah it works now...
Thank you very much for solving this..
i really appreciate our help.
Thank you...
 
Tobias Leon
Greenhorn
Posts: 22
Eclipse IDE Java Opera
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there !!!
Excellent, I'm glad that help you.
See you !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic