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.
Loop over the column names in the table model to build the initial INSERT (and I would use a PreparedStatement).
Something along those lines.
As it stands that'll give you excess ',', but (ignoring that for the moment) it should give you:
INSERT INTO <your table> (col1, col2, col3 etc) VALUES (?,?,?,? etc)
It's the sort of thing that needs to be in its own method so you can concentrate on getting it right without worrying about actually running it.
Then the final string can be used with a prepared statement.
That last part is important.
Finally, you can then look at doing it as a batch call rather than several separate INSERTS.
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad: