I have a java program which is like a search engine where you can type any keyword into the search bar and it will find a matching keyword in the MySQL database and pull up all those entries into a Jtable. There are about 50000 data entries so if I were to type 1.456, all entries that contain this keyword will come up. I have an ID column whereby every entry has a unique ID. I want to be able to export any entries that do not have an ID to a seperate text file. And also if possible, export duplicate IDs.
Asked
Active
Viewed 63 times
0
-
"ID row" - like a star schema? I think you can accomplish this with an appropriate JOIN. – duffymo May 11 '18 at 11:18
-
Sorry I mean column – AadilF1 May 11 '18 at 11:19
-
Sounds like it should be a primary key. Every row should have one. – duffymo May 11 '18 at 11:19
-
If every entry has a unique ID , how would any entries have missing or duplicate IDs? – Kevin Anderson May 11 '18 at 11:21
-
Exactly - a primary key is required and must be unique. You realize that your approach is limited. Lucene/Solr are real search engines. Try those. – duffymo May 11 '18 at 11:30
-
It's not a primary key, it's just a a unique ID for each entity. It's for a crime database, the IDs are unique identifiers for the crime data. There are around 50,000 entities here and there are some that do not have any IDs. I need to be able to export the entities that don't have any IDs to a .txt file – AadilF1 May 11 '18 at 11:39
1 Answers
0
You can just iterate through the set and build up a map of ID->count as integer. In the end you can take all the ones with count > 1 and export them. While building up that map, if you encounter an entry with no key, add it to a separate collection.
Another possibility would be to do it in a custom select right in the DB. Maybe the count function provides what you are looking for: https://www.w3resource.com/sql/aggregate-functions/count-function.php
This is an example for storing in a text file: How do I save a String to a text file using Java?

Andreas Hartmann
- 1,825
- 4
- 23
- 36