File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Table added to SQL database, but with empty records. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Table added to SQL database, but with empty records." Watch "Table added to SQL database, but with empty records." New topic
Author

Table added to SQL database, but with empty records.

Patrick de Kruijf
Ranch Hand

Joined: Mar 02, 2010
Posts: 63
Hello there,

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.


SQL Table


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!


------------------8<------------------
please cut here
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
Hello,

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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table added to SQL database, but with empty records.