Daniel Lawton

Greenhorn
+ Follow
since Aug 18, 2016
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Daniel Lawton

I have now tried implementing a shutdownhook when the 'somethingButton' is pressed. Here is what I've tried.

7 years ago
Hello,

I am running pentaho jobs from command line in Java.
The pentaho job runs fine, and I am able to see the output of the command line inside a JTextArea which updates in real time.#

I now would like a "Stop" button, which does the equivalent of "CTRL+C" in the windows command prompt.

I was trying to use .destroy for the process inside a button, however this doesn't seem to work.
process is a public variable by the way.

Code:
7 years ago
Hello,

I am trying to make a program that allows the user to select a table out of a certain MySQL schema, preview it, edit it (edit cell, delete row, add row) and then save the table back into the MySQL table.

I have managed to achieve this for one table. I now need to make it so it can handle the other tables. The main issue with this is that the tables have different column names/column counts - at the moment I am grabbing the values from column 0,1,2 and putting them into the correct columns in the INSERT statement (LoadID,Active,LoadPath)

I don't know how I would make it so that it gets the column count and then changes the column names in the INSERT INTO statement.

7 years ago

Paul Clapham wrote:I expect that's because the table you are modifying (the one which you can see) is not the table to which you added the listener. What's up with the variable "newTable" which you create at line 41 of your posted code?



I forgot to edit this part out of the question, sorry.

I was messing around with trying to save it to another JTable instead of the original, however I changed this back to saving the change over the original.

This means that the newTable has no meaning anymore
7 years ago
I am trying to make a program that allows the user to edit cells in a JTable by double clicking the cell and this should then update the JTable/TableModel and send this to the original MySQL table.

The issue I'm having is that my TableModelListener is not being triggered when one edits the cell in the JFrame.

I have got it to the point where it successfully truncates the table, but no data is input.

Here is the code.


7 years ago

Junilu Lacar wrote:You're not following standard naming conventions and this makes your code more difficult to read. Only constructors and class/interface names should be capitalized. Method and variable names should be camelcase starting with a lowercase letter.



Apologies for that,

I think I might have found my issue.

No where in my code am I using "setValueAt" so the table isn't actually changing any values. The only reason the changed cells where still there when I opened preview again was due to JFrame remembering them? or something idk.

Either way, I'm not too sure where I would tell it to change the value. I think I would have to loop through the entire table to set the values to whatever they were changed to? I'd have to do this inside the PreviewButton method. (Again, apologies for the naming convention)
7 years ago

Junilu Lacar wrote:Ah, see this is why I don't like yuge methods, they hide disconnects between the intent and what's actually being done; they mislead you almost every time.

Line 5 in your last reply.  What you're doing there is adding a listener.  That's it.  That's like saying "Ok, stand there and wait for something to happen, then do all this stuff."

Your code is still there standing there. Nothing has happened to actually make it execute.  That is, nothing has happened that would trigger the table model to call the tableChanged() method of your listener.



I will look into the documentation for TableModelListener. I thought surely it should count as an event if you changed the table in the jframe but perhaps not.
7 years ago

Junilu Lacar wrote:Your check for columns won't print anything if getColumnCount is zero because you'll never enter the loop. Put the println statement outside the loop. If you still don't get output, then that section of code is not getting executed at all.

And print out the value of changedTableModel.getColumnCount(), not column.



It should come up in the console when I edit the cell and press enter I think?

However, nothing does...
7 years ago

Junilu Lacar wrote:It's possible that getRowCount() and/or getColumnCount() of changedTableModel is returning 0. Did you double check that?



So, I have added in a couple of system.out.println to check the value of column and row.

Literally nothing comes up.

I guess this means that the class isn't being used at all?

7 years ago

Dave Tolls wrote:OK, so previous to correcting the SQL syntax you presumably got a SQLException being thrown and printed to the IDE console?

Ah!
I misread the catch block.
That should say:


This way you'll get all the important information about what has gone wrong and exactly where.



Nothing comes up in the console when the code is run!
7 years ago

Dave Tolls wrote:How are you running this?
I ask, because you should be seeing errors somewhere from that SQLException block.



Just by pressing the green play button at the top of eclipse. There is one "Safety type" error.
7 years ago
Thanks for taking the time to write that detailed response, I'll have a look into it.
7 years ago

Junilu Lacar wrote:Line 104 will result in an invalid SQL statement. If the table is "sometable" the it produces the string "TRUNCATE TABLEsometable". Same kind of problem with the next line.



Upon fixing this, in the preview window I can still change the data, and when the save button is pressed, and I go to look at the MySQL table, nothing changes. If I press Preview again, to bring up the new JFrame containing the JTable data, i get an extra 3 blank columns, with the original MySQL table data appended on the bottom of it. It does however show the changes made from before.
7 years ago
Thanks Junilu, I will fix this and try it out.
7 years ago
Hello,

I have been searching for a while now on how to save JTable data, how to make buttons to do so, and importing data to a MySQL table.

However, what I have managed to complete is quite far from the goal.

What I want to be able to do is edit the JTable inside of the JFrame and then save those changes to a the selected table, which the user will have clicked on via a JComboBox.

What I have working at the moment is a "MainFrame" that shows the combobox containing the schema's table names, and a preview button that opens a new frame with the JTable containing the selected tables data.

Currently, when I press on the SaveButton and then preview the file again, it saves the data inside the JTable, but it isn't writing the data to the MySQL database.
Also, when I press preview again, a new set of blank columns come up to the right, and a new set of data (from the MySQL table) is appended beneath the edited data.

Thanks in advance.


7 years ago