• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Set Jlabels as Database Values

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic