This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a table 'message' in the MySQL database. To make it simple; say, I have three fields in that table: thread_ID, thread_topic, and thread_body. The thread_ID field is AUTO_INCREMENT; therefore, I do not insert any value into that column. The value of that field starts with 1 when the first row is inserted. Now, I have the values for thread_topic and thread_body and want to insert those values into the 'message' table to create the first record in that table. 1. Is thread_ID in column 0 (zero)? and thread_topic in column 1, thread_body in column 2? 2. where and how do I indicate that there is a problem insert a row into the table 'message'? 3. Do I code this way:
[ December 25, 2003: Message edited by: JiaPei Jen ]
I see a couple of things. 1. You can't use a Statement to do what you are trying to do. You need to use a PreparedStatement. 2. You are making it too complicated. Try something like this instead.
As far as how you indicate that there is a problem, you should be catching an SQLException rather mayeb than your custom DatabaseException. An SQLException will tell you if there was a problem interacting with the database. Hope that helps.