File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Display information from a database in a custom made GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Display information from a database in a custom made GUI " Watch "Display information from a database in a custom made GUI " New topic
Author

Display information from a database in a custom made GUI

Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
Greetings,

I am hoping someone can help me. I have trawled through the internet for hours and hours now trying to find a solution to this simple problem and for some reason I cannot find anything that can remotely help. So what I am I trying to do I hear you ask? well its simple:

*****Display information from a database in a custom made GUI *****

I have already created one class that has all the elements of the GUI and a second class that has all the database elements.

When I run the database class (using the instance in the GUI class) all information is shown on screen, exactly in the order that I have it instructed to. This is perfect.

When I run my GUI class, my GUI appears, all my text buttons and labels are fine. This is also perfect.

However my question is this, and this is what I have been looking for for ages now: How do I connect the two together?

How do I make it that the column information in the DB matches the textfield information? How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI.

For the rest of the project I am sorted. I know how to create ActionListeners to add/remove, go back/forth etc, its just this little part is holding the whole thing up.

I will continue my research

The code is shown below, if you need it. Just keep an eye out for the Dutch

Again as always, your help is greatly appreciated

Declan

The GUI Class



The Database Class

Moguluri Ravi Kiran
Ranch Hand

Joined: Apr 16, 2010
Posts: 62

Declan Dee wrote:
How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI.


I think ResultSetMetaData serves you.
Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
Moguluri Ravi Kiran wrote:
Declan Dee wrote:
How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI.


I think ResultSetMetaData serves you.


Hi Kiran,

I have used this before. I thought it was just for getting what types of data where in columns (amoungst other things)
Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
Hi,

I have done some more research and I found something that might be useful but I am not sure where it is supposed to go.

I know I have to bring in the value of the column from the MySQL database. When I usually want to bring in something to a textfield, I use this command:



So now I have created this code:



The only problem I have now is, where do I put this?

I was thinking of making a method called:



And putting in all the colums and corresponding textfields that I need. The problem is that if I put it into the GUI class, it cannot see the resultset variable...
and If I put it in the database class it wont see the textfield variables.

But at least a step forward!
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1821
    
    7

Hint: the comment "Should not be void???!" could be right on the money.
Unless you're bound to that interface?

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
Jelle Klap wrote:Hint: the comment "Should not be void???!" could be right on the money.
Unless you're bound to that interface?


Im sorry I dont understand

I am not bound to it
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
I think this thread would sit better on our databases forum. Moving.
Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
I have solved my problem

At the start I had two questions:

1 - "How do I make it that the column information in the DB matches the textfield information? How do I make it that the column ‘name’ in my MySQL database shows up in the name texfield in my GUI"

That I solved with the method that I mentioned above.

2 - "How do I connect the two together? "

This was where I was having all my issues. In the end (I guess I am still a beginner) it was very simple and I feel very stupid.

But the solution was to call that method (the one that I have typed above, its called 'getDatabaseValues') from the console, in the main method and thats a bingo!



I need to check a few small things with my instructor and I will post the entire code tomorrow





Declan Dee
Greenhorn

Joined: May 04, 2010
Posts: 20
Hi,

For anyone that is interested, this is the complete solution:

[b]The program in ONE COMPLETE CLASS[/b]



Now the program in two seperate classes. One class for the design of the GUI and one for the connection to the database



Now the class for the database connection

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Display information from a database in a custom made GUI