Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

updating mysql table using jtable rows value at once  RSS feed

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a MySQL Table with the following columns [itemCode, itemCount],
and I have a jTable with the Columns [itemCode, itemCount].

jTable load its data from the MySQL table, so they both have the same data, but the jTable could also have only partial data of the MySQL Table ( not all item ).

now if I edit the value of itemCount in jTable,

How do I then can update the change all at once to the MySQL table ?

this is my Code ( which isnt working as intended ) :



I am not fluent in english, please ignore any misspelled words
 
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
 
Carey Brown
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its been a while since I did some JDBC work so check me on this.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Its been a while since I did some JDBC work so check me on this.



Big Thanks, Super! I am so dull, its working like a charm!
 
Carey Brown
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that executeBatch returns a list (array?) of how many rows were updated. Maybe you don't need to check but it's worth thinking about.
 
Rancher
Posts: 3010
20
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already asked and answered hours ago: https://stackoverflow.com/questions/52671116/updating-mysql-table-using-where-parameter-from-jtable-cell/52672310#52672310

In fact the same answer was given there before you even posted the question here.

This is why we get so frustrated when you cross post the same question:

1. You don't even take the time to read the answers on the other forums.
2. You don't even take the time to let people know the problem has been solved.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rob Camick wrote:Already asked and answered hours ago: https://stackoverflow.com/questions/52671116/updating-mysql-table-using-where-parameter-from-jtable-cell/52672310#52672310

In fact the same answer was given there before you even posted the question here.

This is why we get so frustrated when you cross post the same question:

1. You don't even take the time to read the answers on the other forums.
2. You don't even take the time to let people know the problem has been solved.



Yes, you answered first, but as I told before, I am not fluent in English, and the code in your answer was only partial, not complete, I wasnt able to try to figure out that the SQL Command should be moved outside the for loop, for it to be working, so I wasnt able to solve my problem with your answer, then I got a full and clearer piece of code as answer here.

This is the first time I registered myself here, because 4-5 times I was only using stackoverflow only, but due to my hard time explaining my problems and my english skill, I was kinda frustrated and having hard time waiting for answer there, because I need a fast answer since I am working on a project on my own.

the Time I was posting this, was around 6-8 am in my country, I wasnt sleeping the whole night, for almost 12-14 hours straight to work on my project, so the time I was able to solve my project I wasnt remember to check my question at stackoverflow, I was going straight to the bed.

So once Again, I think this is just a misunderstanding.

I wont even feel the need to register here if I dont find myself having hard time delivering my question on the other side, I always need to edit my question for countless time there because people there tend to get confused with my intention, I dont blame anyone, I just blame myself,it was frustrating, so I thought I maybe could have a better luck on other forum, so I registered here.

I will accept your answer there, and apologize there too if needed, and sorry for so late respond, I just woke up.

Thank you very much.
 
Carey Brown
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At Code Ranch we don't have a problem with cross posting but to be polite a comment mentioning that this is a cross post is appreciated.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:At Code Ranch we don't have a problem with cross posting but to be polite a comment mentioning that this is a cross post is appreciated.



I will keep that in mind, and take that into consideration from now on everytime I want to post a new Question.

I am not familiar with forum, because as stated, I am not good at english ( not being my native language ) and I tend to have hard time understanding rules and else, if it not for my project frustratuin I wont even dare registering and posting on forums including here.

Thnk you very much for the support.
 
Carey Brown
Bartender
Posts: 5632
56
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have quite a few members for whom English is not their native language. We all seem to survive it and I wouldn't let that stop you from coming back again.
 
Dave mann
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:We have quite a few members for whom English is not their native language. We all seem to survive it and I wouldn't let that stop you from coming back again.



Glad to know that, Thanks for the awesome support, I'll enjoy my stay.    
 
Rob Camick
Rancher
Posts: 3010
20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I wasnt able to try to figure out that the SQL Command should be moved outside the for loop, for it to be working,



Notice in my answer I suggested you keep the solution simple by first just trying to update a single row using the PreparedStatement so you understand how to use multiple tokens in the statement?

I then stated that I had never used a batch updated before.

So if in fact it does make a difference to invoke the "prepareStatement(...)" method outside of the loop it would have been nice for you to respond to my answer stating that the token replacement worked fine but that the "prepareStatement(...)" needs to be outside the loop when using batch processing.

This way you show me that you actually read my answer and tried it.

Also, you are not contributing to the forum because I learned something new and others who read the answer in the other forum will also learn something new.

Again, the point of a forum is to provide feedback, not just ignore answers.
 
Rancher
Posts: 3921
45
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just one thing about the code above:


The MySQL driver does not require this code, as it registers itself.
However, even if it did not do that this line would be unecessary as you clearly already have a connection, and so the driver must already have been loaded.
 
We noticed he had no friends. So we gave him this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!