Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Display data from database in label.  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i'm trying to create a digital agenda where i store people's name and phone numbers.
I succeded in inserting data from my form ( created with java fxml ) in my database, but i can't display the data from the database in a label.


The last label ("labelDone.setText("Done!");") works fine, but the label ("labelContact.setText(Integer.toString(stmt.executeUpdate(sql1)));") doesn't work. It works if i move it down next to labelDone but i need it up there where is my sql statement. What can i do in this case?
 
Rancher
Posts: 427
6
Fedora IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think maybe you are using the wrong method. Select is not an update.  You want to execute a query. After executing the query a resultset or some kind of data object will be returned.  You get your data from that.
 
Marshal
Posts: 5987
155
Chrome Eclipse IDE Java Postgres Database Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the area of code we're talking about:
First, in line 37, print something that will indicate your error.  Otherwise your errors are just disappearing.
Next, you are performing an executUpdate() in line 29, but you're not updating anything.  You could try
if you want to see how many records exists and use this code (in some form):
Does that make sense to you?
 
Master Rancher
Posts: 4074
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute's correct in that you need to use an executeQuery.

Also, you should be using a PreparedStatement for the query, especially since you are accepting data from the user:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!