Results 1 to 17 of 17
- 05-25-2012, 12:11 PM #1
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
JComboBox with database making problem on retrive
HI All!

In my project i am using JComboBox with Database
I wants to retrives the date from database to JComboBox
my code is
I have near with 50 record in that table.Java Code:public void showcom() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip","root","root"); PreparedStatement ps=conn.prepareStatement("select EmployeeID from newemp"); //PreparedStatement ps=conn.prepareStatement("select * from newemp"); ResultSet rs=ps.executeQuery(); if(rs.next()) { combob.addItem(rs.getString("EmployeeID")); } } catch(Exception e) { } }
but it showing the first employee id only, doesn't show the remaining Employee ID's
what is the problem i did in my cod,
can anyone Guide me..,
Thank you..,
- 05-25-2012, 12:41 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: JComboBox with database making problem on retrive
You're only adding one record to your combo box, no matter how many records are stored in your table; add a loop somewhere in your code, not just an if-statement.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-25-2012, 12:46 PM #3
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: JComboBox with database making problem on retrive
Thank You Mr.Jos!
i will try now self..,
Thanks For your Idea sir..,
- 05-25-2012, 01:20 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: JComboBox with database making problem on retrive
Yes, that 'if' should be a 'while'.
Please do not ask for code as refusal often offends.
- 05-25-2012, 01:25 PM #5
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: JComboBox with database making problem on retrive
sir!
because of my mistaken i receive the same problem,
the first records only repeated as numbers of rows..,
how to i correct in that loop sir..,
Java Code:if(rs.next()) { for(int i=0;i<=rs.getRow();i++) { jComboBox1.addItem(rs.getString("EmployeeID")); } }
- 05-25-2012, 01:30 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: JComboBox with database making problem on retrive
You're using the wrong method (read the API documentation for the ResultSet interface); you should use a combination of rs.next(), rs.getXXX() method calls.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-25-2012, 01:38 PM #7
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: JComboBox with database making problem on retrive
sir i try with google help,
at the time i was found the fallowing samples sir..,
Add Items in JComboBox from Access Database
populate jCombobox with database data
in that sample code are using the same methods that's why i use..,
ok sir! please guide me, what i have to do now..,
- 05-25-2012, 01:55 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: JComboBox with database making problem on retrive
RoseIndia is an extremey crappy site; use a simple loop:
kind regards,Java Code:while (rs.next()) { // fetch a column and add it to your combo box }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-25-2012, 03:52 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: JComboBox with database making problem on retrive
Which is what I said...it's amazing how sometimes our posts simply go invisible.
Please do not ask for code as refusal often offends.
- 05-25-2012, 03:56 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
- 05-25-2012, 04:14 PM #11
Re: JComboBox with database making problem on retrive
OT (partly): I wish Google would catch on to whatever nefarious scheming keeps that worthless stinking waste of bandwidth at or near the top of their searches.
The first time I discovered the site, I found a code 'example' that extended JFrame but wasn't used as one; the JFrame that was shown was declared and constructed inside a method; a local variable. Months later, they hadn't corrected the code. Chances are nobody even read my feedback.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-25-2012, 04:29 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
Re: JComboBox with database making problem on retrive
Are you criticizing that beautiful gem? That source of wisdom? The holy knowledge base that enlightens millions of poor souls, searching for the ultimate truth? tsk, tsk ...
kind regards,
Jos ;-)When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-25-2012, 04:55 PM #13
Re: JComboBox with database making problem on retrive
Their servers should be immersed in the Ganges. Along with their coders, who by no stretch of the imagination can be called programmers.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 05-29-2012, 09:04 AM #14
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: JComboBox with database making problem on retrive
sorry for the late response sir..,
i am living in out of city that's why i unable to get good internet connection,
that is the only reason for my invisibility..,
forgive me please for my invisibility with this Forum, while you response for my post..,
- 05-29-2012, 10:19 AM #15
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Re: JComboBox with database making problem on retrive
Thanks For My Guides
.gif)
Jest i try my self, it is working well
instead of using "if" i used "while" loop and remove the "for" condition
my code is
Java Code:try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/payslip","root","root"); PreparedStatement ps=conn.prepareStatement("select EmployeeID from newemp"); ResultSet rs=ps.executeQuery(); while(rs.next()) { { jComboBox1.addItem(rs.getString("EmployeeID")); } } } catch(Exception e) { JOptionPane.showMessageDialog(rootPane, e); }
it add all the elements from my MySQL to Java Coding..,
Thank you For All..,
- 05-29-2012, 11:26 AM #16
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: JComboBox with database making problem on retrive
It's not your invisibility.
It's that you didn't seem to acknowledge the answers given by us here.
If you didn't understand them then just ask, but not taking in what we say leaves us a little lost as to what problems you are having.Please do not ask for code as refusal often offends.
- 05-29-2012, 01:29 PM #17
Senior Member
- Join Date
- Jan 2012
- Location
- TamilNadu
- Posts
- 165
- Rep Power
- 2
Similar Threads
-
link jcombobox with database
By amer in forum NetBeansReplies: 2Last Post: 10-15-2010, 08:32 PM -
Jcombobox with mysql database
By kesariramachandran in forum AWT / SwingReplies: 2Last Post: 05-18-2010, 09:32 PM -
populate jCombobox with database data
By joeyxaza in forum JDBCReplies: 0Last Post: 01-19-2009, 04:30 PM -
jComboBox and database
By pravin2008 in forum AWT / SwingReplies: 3Last Post: 08-25-2008, 04:08 PM -
Making a Table Row with JPanel Composed of JTextField and JComboBox Selectable
By datechie in forum AWT / SwingReplies: 2Last Post: 07-30-2008, 12:33 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks