I use the MySQL database and the Tomcat 4.1.18 web server. I try to insert a record to a table message_thread
in the MySQL database. The first column of that table is for the ID of each recored. I created that column (field) with
INTEGER AUTO_INCREMENT. Therefore, I did not mention that field in the method that inserts records. Nonetheless,
I got an internal server error and the root cause is:
>
org.apache.artimus.message.exceptions.MessageDAOSysException: Error executing SQL in ThreadHandler.createThread.
at org.apache.artimus.message.dao.MySQLMessageDAO.createThread(MySQLMessageDAO.java:54)
I do not know how or where to start investigaing problems and need your guidance.
My code is shown below:
package org.apache.artimus.message.dao;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.apache.artimus.message.exceptions.MessageDAOSysException;
import org.apache.artimus.message.exceptions.ObjectNotFoundException;
import org.apache.artimus.ConnectionPool.DBConnection;
public class MySQLMessageDAO implements MessageDAO
{
public void createThread( String receiver, String sender, String title,
String lastPostMemberName, String threadTopic,
String threadBody, Timestamp threadCreationDate,
Timestamp threadLastPostDate, int threadType,
int threadOption, int threadStatus, int threadViewCount,
int threadReplyCount, int threadDuration )
throws MessageDAOSysException
{
Connection conn = null;
PreparedStatement stmt = null;
String insertSQL = "INSERT INTO message_thread( message_receiver, message_sender, article_title, last_post_member_name, thread_topic, thread_body, thread_creation_date, thread_last_post_date, thread_type, thread_option, thread_status, thread_view_count, thread_reply_count, thread_duration ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try
{
conn = DBConnection.getDBConnection();
stmt = conn.prepareStatement( insertSQL );
stmt.setString( 1, receiver );
stmt.setString( 2, sender );
stmt.setString( 3, title );
stmt.setString( 4, lastPostMemberName );
stmt.setString( 5, threadTopic );
stmt.setString( 6, threadBody );
stmt.setTimestamp( 7, threadCreationDate );
stmt.setTimestamp( 8, threadLastPostDate );
stmt.setInt( 9, threadType );
stmt.setInt( 10, threadOption );
stmt.setInt( 11, threadStatus );
stmt.setInt( 12, threadViewCount );
stmt.setInt( 13, threadReplyCount );
stmt.setInt( 14, threadDuration );
stmt.execute();
}
catch( SQLException se )
{
se.printStackTrace();
throw new MessageDAOSysException("Error executing SQL in ThreadHandler.createThread."); // line 54 where the problem occurred
}
finally
{
if ( conn != null )
{
try
{
stmt.close();
stmt = null;
conn.close();
}
catch( SQLException sqlEx )
{
System.out.println( "Problem occurs while closing " + sqlEx );
}
conn = null;
}
}
}
.....
.....
}