@Override
protected void writeInternal(final LogEvent event) {
StringReader reader = null;
try {
if (!this.isConnected() || this.connection == null || this.connection.isClosed()) {
throw new AppenderLoggingException(
"Cannot write logging event; JDBC manager not connected to the database.");
}
int i = 1;
for (final Column column : this.columns) {
if (column.isEventTimestamp) {
this.statement.setTimestamp(i++, new Timestamp(event.getMillis()));
} else {
if (column.isClob) {
reader = new StringReader(column.layout.toSerializable(event));
if (column.isUnicode) {
this.statement.setNClob(i++, reader);
} else {
this.statement.setClob(i++, reader);
}
} else {
if (column.isUnicode) {
this.statement.setNString(i++, column.layout.toSerializable(event));
} else {
this.statement.setString(i++, column.layout.toSerializable(event));
}
}
}
}
if (this.statement.executeUpdate() == 0) {
throw new AppenderLoggingException(
"No records inserted in database table for log event in JDBC manager.");
}
} catch (final SQLException e) {
throw new AppenderLoggingException("Failed to insert record for log event in JDBC manager: " +
e.getMessage(), e);
} finally {
Closer.closeSilent(reader);
}
}