Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jTable connected with MySQL problem with buttons  RSS feed

 
vasilhs alexandropoulos
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??
 
E Armitage
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?
 
K. Tsang
Bartender
Posts: 3624
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: 3624
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!