I have the following PreparedStatement code:
String sql =
"insert into message " +
"(msg_pk, msg_message, msg_chtFK, msg_datetime, msg_usrFK) " +
" VALUES(null,?,?,?,?)";
try
{
PreparedStatement ps = connection.prepareStatement(sql);
System.out.println("ps = " + ps.toString());
//
test values below
ps.setString(1, "Hello");
ps.setInt(2, 1 );
ps.setTimestamp(3, ts ); // SQL Timestamp
ps.setInt(4, 1);
rowsAffected = statement.executeUpdate(sql);
.
.
.
When I try to "executeUpdate(sql)", I'm getting the follwoing error:
"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '?,?,?,?)' at line 1"
If I break up this statement and don't use the PreparedStatement, the insert, with 'null' for the first parameter correctly gets MySQL to auto-increment the msg_pk field.
Also, on another table, I can just use ps.setString() and the PreparedStatemetn works then too.
I'm thinking that perhaps the insert can't handle the TimeStamp or something.
Anybody run into this behavior?
Suggestions?
Thanks very much in advance.
-- Mike