Я создал подготовленный оператор, который должен обновлять строку, однако строка не обновляется.
/**
* Sets the last modified date of the Index to Now();
* Automatically gets the number of files and total size of files in index that are included in the index and sets that data too.
* @return
* @throws SQLException
* @throws ClassNotFoundException
* @throws UnexpectedException
*/
public void MarkUpdated() throws ClassNotFoundException, SQLException, UnexpectedException
{
Connection connection = null;
PreparedStatement statement1 = null;
PreparedStatement statement2 = null;
PreparedStatement statement3 = null;
ResultSet rSet1 = null;
ResultSet rSet2 = null;
// First, lets obtain the file count
try
{
Integer count;
connection = ConnectionMgr.getConnectionToSc1();
connection.setAutoCommit(true);
statement1 = connection.prepareStatement
("SELECT COUNT(*) FROM indexFiles WHERE IndexID=? AND IndexUUID=?");
statement1.setLong(1, IndexID);
statement1.setString(2, IndexUUID);
rSet1 = statement1.executeQuery();
if (rSet1.next())
{
count = rSet1.getInt(1);
}
else
{
throw new UnexpectedException("Failed to Mark Updated - Couldn't get file count?");
}
// Now lets obtain the total amount of disk space these files are occupying
// This is a bit more complicated
Long size;
statement2 = connection.prepareStatement
("SELECT SUM(FileSize) FROM files WHERE FileUUID IN "
+"(SELECT FileUUID FROM indexFiles WHERE IndexID=? AND IndexUUID=?)");
statement2.setLong(1, IndexID);
statement2.setString(2, IndexUUID);
rSet2 = statement2.executeQuery();
if (rSet2.next())
{
size = rSet2.getLong(1);
}
else
{
throw new UnexpectedException("Failed to Mark Updated - Couldn't get sum of file sizes?");
}
// Now we mark the index as updated with the new file count
statement3 = connection.prepareStatement
("UPDATE indexes SET FileCount=? AND Size=? WHERE IndexID=? AND IndexUUID=?");
statement3.setInt(1, count);
statement3.setLong(2, size);
statement3.setLong(3, IndexID);
statement3.setString(4, IndexUUID);
//if (1 != 0)
//{
// throw new UnexpectedException("Count " + count + " Size " + size + " IndexID " + IndexID + " IndexUUID " + IndexUUID);
//}
int rowsUpdated = statement3.executeUpdate();
if (rowsUpdated != 1) {throw new UnexpectedException("Failed to mark an index as updated: Index UUID is " + IndexUUID);}
} finally {
DbUtils.closeQuietly(rSet1);
DbUtils.closeQuietly(rSet2);
DbUtils.closeQuietly(statement1);
DbUtils.closeQuietly(statement2);
DbUtils.closeQuietly(statement3);
DbUtils.closeQuietly(connection);
}
}
Умышленно выброшенное исключение
Умышленно выданное исключение
Вы можете видеть из моего кода отладки, что я пытался вызвать исключение, чтобы убедиться, что все установлено правильно. Я могу подтвердить, что в моей таблице есть строка с этим IndexID / UUID.
Оператор выполнен, и не генерируется исключение, указывающее, что произошло обновление - однако при проверке моей таблицы эти значения не обновляются.
Я пытаюсь выяснить, почему это может быть? Я проверил и не установил autocommit в false при построении моего соединения. Для столбцов FileCount и Size по умолчанию задано значение «0», но значения по умолчанию не должны переопределять значения операторов, верно?
Заранее спасибо за помощь