The following code gives a BatchUpdateException and I have no idea why.
public void createContactmoment(Document document) {
try {
c = MySqlDAOFactory.getInstance().getConnection();
//
c.setAutoCommit(false);
//
String sql = "insert into index(iddocument,chapter,chapterdate)"
+ "values (?,?,?)";
//
prest = c.prepareStatement(sql);
//
int count = 1;
//Formatter for the time
DateTimeFormatter format = DateTimeFormat.forPattern("dd-MM-yyyy");
//
while (count <= Integer.parseInt(document.getTeachingWeeks())
|| count == document.getAllDates().size()
|| count == document.getContactMomentList().size()) {
//
if (MysqlDocumentDAO.getInstance().findByName(
document.getName()) == -1)
return;
//
prest.setInt(1,MysqlDocumentDAO.getInstance().findByName(
document.getName()));
if (document.getContactMomentList().get(count) != null)
prest.setString(2,document.getContactMomentList().get(count));
else
prest.setString(2, "No contactmoment found, but expected");
//
if (document.getAllDates().get(count) != null)
prest.setString(3,(format.print(document.getAllDates().get(count))));
else
prest.setString(3, "Na date found, but expected");
//
prest.addBatch();
//
count++;
}
//
prest.executeBatch();
c.commit();
//
} catch (SQLException e) {
JdbcLogging.info("Dit trad op bij het uitvoeren van de batchtaak (contactMoments)"+ " :" + e);
} finally {
MySqlConnectionFactory.getInstance().closeStatement(prest);
MySqlConnectionFactory.getInstance().closeConnection(c);
}
}
The error I see in my log is :
INFO JdbcLogging:25 - Dit trad op bij het uitvoeren van de batchtaak (contactMoments) :java.sql.BatchUpdateException: 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 'index(iddocument,chapter,chapterdate)values (44,'Examen; * Verdedigen project','' at line 1
So it seems that in the last update I'm missing some data. The data I want to write does excist (I checked with a system printline.
Any suggestions would be more then welcome.