my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes problem in fetching values in combobox from databases. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "problem in fetching values in combobox from databases." Watch "problem in fetching values in combobox from databases." New topic
Author

problem in fetching values in combobox from databases.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Apr 17, 2012
Posts: 22

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.


Murphy's Law
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2

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

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2

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

Joined: Apr 17, 2012
Posts: 22

Hi there !!!

Try this:


I'm doing for SWT and it works
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
i tried this:


but my jcombobox are not changing their values..
Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2

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

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2

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

Joined: Apr 17, 2012
Posts: 22

Hi there !!!

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

Regards !!!
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
okay..
thank you very much Tobias Leon
Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

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"



[Thumbnail for split.jpg]

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Aug 20, 2011
Posts: 982
    
    2
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

Joined: Apr 17, 2012
Posts: 22

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

Joined: Aug 20, 2011
Posts: 982
    
    2
okay...
thank you very much...
Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

Hi there !!! Sorry for wait so long.




Regards !!!



[Thumbnail for jcombo.jpg]

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
hii thank you for the reply..
if i initialize comboboxes code will not work..

Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

Hi there !!! Morning !!!

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

Regards !!!
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 982
    
    2
hii, good evening..
yeah it works now...
Thank you very much for solving this..
i really appreciate our help.
Thank you...
Tobias Leon
Greenhorn

Joined: Apr 17, 2012
Posts: 22

Hi there !!!
Excellent, I'm glad that help you.
See you !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in fetching values in combobox from databases.
 
Similar Threads
Passing Date from HTML Form to JSP/Action Handler
Online Exam Problem!!!
My thoughts about the search dialog implementation
UrlyBird - Question about find method
Dependent/chain comboboxes on same jsp page