Table added to SQL database, but with empty records.
Post by:Patrick de Kruijf
, Ranch Hand
I'm trying to add text from 2 JTextFields and 2 JTextAreas to 4 records in one sql table. I have a connection with the database, there is even a new table added if I push my 'add' button, but the records are empty, there is no text in it.
I tried a lot of different things, like replacing ' by `. The results improved, but my code won't add the text. Can somebody help me?
I have added only the code that I think is relevant for my question.
Here is my GUI class wich builds the GUI and converts the userinput from the textArea
This is the write method, that lives in the public class MenuKaart. This method should add the user input from the gui class to the database
Thanks in advance for your precious time and effort!
Post by:Ireneusz Kordal
, Ranch Hand
the first thing you should do is to log or print errors cacthed by exception handler in this code fragment:
There is likely an exception thrown by executeUpdate, but you are not aware of this because you simply skip errors.
The error code/message can give you a clue what is wrong.
Post by:Paul Clapham
And the second thing you should do is to close your connection after you're finished using it. Otherwise it's possible that, since you didn't commit your transaction, it will not be written to the database.
And also you should use a PreparedStatement, not a Statement. Your idea of building the SQL as a string is subject to bugs (what if one of the strings has a quote character in it?).
And when you close your connection, do that in a finally-block so that it gets closed even if exceptions are thrown.
Are you okay? You look a little big. Maybe this tiny ad will help: