• 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

jTable connected with MySQL problem with buttons  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am making a car rental software using NetBeans 8.0.2 i am facing a problem i have created a jForm and inside it a jTable with 4 button and 6 text areas each text area represents a table section in my database they are all fully connected to eachother
i need to create a button to update, to insert and delete row in the jTable and automatically update it to the MySQL this is my code:

could someone help me please??
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really should not be mixing jdbc code with swing code. Write a DAO layer (can be just one class) that knows nothing about swing and test that you can create, read,update, delete records successfully before plugging it into your interface code. Also, you should be doing all the database connection code on a thread separate from your user interface thread. Read up on how to use the SwingWorker to achieve that.




 
vasilhs alexandropoulos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im kinda new to programming and i need to create a car rental software do you have any suggestions?
 
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I see your button2 (update) has some code in it. Yet I don't see why you starting with update, the insert button should be the first crack at it.

Don't worry about the connection yet. First, are you able to get the values from the text fields and match to the variables for the SQL statement?

Since you are using PreparedStatement, to prevent SQL injection you can do this instead:


About the database connection, how are you getting it?
 
vasilhs alexandropoulos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im connecting with a jtable from a mysql database and yes i see everyting ok in text boxes, about the insert button i still dont know how to do that :/
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For insert button, the logic should be similar to update/delete. Instead of the sql is "update ...." will become "insert ....".

As long as you got the sql correct, it should be fine.
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!