Results 1 to 3 of 3
Thread: Java/SQL Removing double data
- 05-12-2010, 10:59 PM #1
Member
- Join Date
- May 2010
- Posts
- 1
- Rep Power
- 0
Java/SQL Removing double data
I know this might seem like a simple query problem [and it probably is but not for me :D].
The problem is the following that using the DISTINCT method in the query does not remove the double data. I tried using DISTINCT only on gemeente, but then the data does not show up in my ComboBox.
The point is is that I remove the double data from the gemeente column, which contains a bunch of towns and their postal codes. Then I need to list those towns in a ComboBox but applying DISTINCT to gemeente only works as a query in SQL, but then I do not see the data in my combobox.
StudentFrame that loads the data into the comboboxJava Code:public Vector<jstageGemeente> getjStageGemeente() { Statement stmt = null; ResultSet rs = null; jstageGemeente gemeente = null; Vector <jstageGemeente> resultaat = new Vector<jstageGemeente>(); try { stmt = connection.createStatement(); rs = stmt.executeQuery("SELECT DISTINCT id, postcode, gemeente FROM jstageGemeente ORDER BY gemeente"); while (rs.next()) { gemeente = new jstageGemeente(); gemeente.setId(rs.getInt(1)); gemeente.setPostcode(rs.getInt(2)); gemeente.setGemeente(rs.getString(3)); resultaat.add(gemeente); } }
Java Code:public class StudentFrame extends JFrame implements ActionListener { private Container content; private JPanel topLeft, topRight, bottomLeft, bottomRight; private JComboBox gemeentenBox, sectorBox, soortBox; private JTextField aantalVeld; private JButton zoekenButton; private DAjstageLogin daLogin = null; private DAjstageBedrijf daBedrijf = null; private DAjstageGemeente daGemeente = null; private DAjstageKeuze daKeuze = null; private DAjstageSector daSector = null; private DAjstageSoort daSoort = null; private DAjstageStudent daStudent = null; private DAjstageOpdracht daOpdracht = null; public StudentFrame(DAjstageBedrijf daBedrijf, DAjstageKeuze daKeuze, DAjstageGemeente daGemeente, DAjstageSector daSector, DAjstageOpdracht daOpdracht, DAjstageSoort daSoort, DAjstageStudent daStudent, DAjstageLogin daLogin) throws Exception { this.daGemeente = daGemeente; this.daSector = daSector; this.daOpdracht = daOpdracht; this.daStudent = daStudent; this.daKeuze = daKeuze; this.daLogin = daLogin; this.daSoort = daSoort; this.setLocation(150,150); setTitle("Welkom"); setSize(1000,750); opbouwScherm(); addWindowListener(new VensterHandler()); setVisible(true); this.setResizable(false); } public void opbouwScherm(){ content = getContentPane(); content.setLayout(null); JComboBox gemeentenBox = new JComboBox(daGemeente.getjStageGemeente()); gemeentenBox.insertItemAt("geen voorkeur", 0); JComboBox sectorBox = new JComboBox(daSector.getjStageSector()); sectorBox.insertItemAt("geen voorkeur", 0); JComboBox soortBox = new JComboBox(daSoort.getjStageSoort()); soortBox.insertItemAt("geen voorkeur", 0); JTextField aantalVeld = new JTextField(); JButton zoekenButton = new JButton("Zoek"); JLabel gemeentenLabel = new JLabel("Locatie bedrijf:"); JLabel aantalLabel = new JLabel("Werkzame informatici:"); JLabel sectorLabel = new JLabel("Sector stagebedrijf:"); JLabel soortLabel = new JLabel("Soort stage:"); //comboboxen gemeentenBox.setBounds(5, 30, 150, 20); sectorBox.setBounds(160, 30, 325, 20); soortBox.setBounds(495, 30, 140, 20); aantalVeld.setBounds(625, 30, 135, 20); //labels gemeentenLabel.setBounds(5,10,120,20); sectorLabel.setBounds(160,10,120,20); soortLabel.setBounds(495,10,120,20); aantalLabel.setBounds(625,10,135,20); //buttons zoekenButton.setBounds(800,30,80,20); content.add(gemeentenBox); content.add(sectorBox); content.add(soortBox); content.add(aantalVeld); content.add(gemeentenLabel); content.add(sectorLabel); content.add(soortLabel); content.add(aantalLabel); content.add(zoekenButton); }
- 05-13-2010, 03:08 PM #2
Senior Member
- Join Date
- Mar 2010
- Location
- Manila, Philippines
- Posts
- 257
- Rep Power
- 4
Well this thread doesn't really belong to this location.
It must be placed in the database section.
Anyways,
I think I have solved your problem.
You can't have two columns to "DISTINCT". You must only select one column.
Or you may add a "GROUP BY" phrase to which column you must have the "DISTINCT" phrase working.
The GUI code on the other hand, is perfectly coded.Every project, package, class, method, variable, syntax, algorithm, etc.
are registered in my memory bank. Thanks to this thread.
- 05-13-2010, 03:44 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
double a * double b = weird output
By GPB in forum New To JavaReplies: 3Last Post: 03-26-2010, 10:40 AM -
double or float for importing data?
By tyang in forum New To JavaReplies: 2Last Post: 02-10-2010, 09:30 AM -
double and float value in java
By arvindmer in forum New To JavaReplies: 6Last Post: 05-28-2009, 04:51 PM -
Double.valueOf() vs Double.parseDouble()
By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM -
Data Pipeline 2 - Data Transformation Toolkit for Java Released
By dele in forum Java SoftwareReplies: 0Last Post: 10-31-2008, 02:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks