Great that you figured it out yourself!
There are still a few problems with your code. First of all, it is really a bad idea to catch an exception and do nothing, such as:
When the exception actually occurs, your code will silently ignore it and continue. These bugs are very hard to understand ("my code doesn't fail but also doesn't do what it should"), so it's a good idea to get the code right at the first try.
I would even discourage using just
It's somewhat better than the above, but in real life people don't look at the logs or into the console very often, so these bugs tend to get overlooked anyway. The best approach in my opinion is to throw a
RuntimeException with a good description of the problem and let it be. Your application might then catch and somehow process unchecked exceptions at the top level globally, or it would fail when it occurs, which is actually a very good and desirable outcome for unexpected exceptions.
It is also really necessary to correctly close the resources in the
finally clause. Unless you're on
Java 7, where you could (and should) use the try-with-resources statement that takes care of it all on its own.
And lastly, it's much better (and generally easier) to use PreparedStatement instead of concatenating the values into the SQL statements. The most important reasons are summed up nicely
here.