This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of AWS Security and have Dylan Shields on-line!
See this thread for details.
Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Displaying SELECT results into swing interface

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing a search interface in eclipse working with mysql. I believe I have the SELECT statement right, but I am unsure of how to display the results of the search on my interface. I am working on the search for the 'city search' currently and haven't finished the select statement for the 'tag search' yet as I don't want to get ahead of myself. Is 'result' used to display the selected values from my database table or something else?

I originally had a JList instead of a JTable to try and display the search results in but switched it. It wasn't working right than either.

 
Marshal
Posts: 25598
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That all looked pretty good to me the first, and second, time I looked through it. You've got a JTable, you fill a TableModel with data from the ResultSet, you make that be the JTable's model -- that's all right and should work.

Then the third time I scanned the code:



Yup, that looks more or less right. There could be some details you got wrong there which I didn't recognize but then I don't write this code every day.



And then you throw that table model away and replace it with another one? Don't do that.

By the way it's clear that you weren't happy about the output of your code. It would help in future if you describe what you saw and how it differs from what you expected.
 
Taylor Manley
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want the output to be displayed in the Jtable, but I don't get any output at all. So the lack of output comes from creating a different .getModel?
 
Paul Clapham
Marshal
Posts: 25598
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not necessarily. It might be that your query doesn't return any rows. But I'd fix the known error first.

I'm assuming that you see an empty JTable in your GUI? You haven't said what you do see yet.
 
Taylor Manley
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So when I run the program, my gui pops up and the JTable is empty. If I enter something for the "?" parameter and hit the "search city" button, I get no response from the program. I do have at least row that wold fill the parameter, but I get no return output into the JTable and it remains empty.
 
Taylor Manley
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe I got it to work. I'm now receiving an output in the Jtable. Thank you for all your help.

One more question, is there a way to have the SELECT statement search for semantics or partial words or does it only search for verbatim results?

My current code for the database part is


 
Paul Clapham
Marshal
Posts: 25598
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good work! Glad to hear it's working.

Taylor Manley wrote:One more question, is there a way to have the SELECT statement search for semantics or partial words or does it only search for verbatim results?



Yes, I'm sure you can do that. I think you'd use the LIKE operator rather than the = operator.
 
Hey cool! They got a blimp! But I have a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic