• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Set Jlabels as Database Values

 
Muha Hassan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a program whereby the User can enter expenses of his employees.

now the Jlabels should be dynamic. it. I want the texts in the Jlabels to contain the values from the Database.

for example. if I have 10 employees, employeeExpenseForm should have 10 Names. if I delete an employee record. EmployeeExpenseForm should have 9 names.

Thanks in Advance
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Connecting to and getting values from database should be fairly simple in GUI programs.

First create JDBC connection and write sql to select the relevant tables. Once you have those values from database, creating the JLabels by looping through the result set.
 
Muha Hassan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

when looping through, do I create my Jlabels in the loop. I don't get that part.

I want the number of Jlabels to be the same as the Number columns in the database.
 
K. Tsang
Bartender
Posts: 3604
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muha Hassan wrote:I want the number of Jlabels to be the same as the Number columns in the database.


I don't know how your table is setup. But working with rows rather than columns in this particular case will simplify your coding a whole lot.

For row based result set


Of course you want to put your result set in a list for the GUI to use rather than writing sql (doing DB stuff) directly in GUI classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!