Code example for PreparedStatement

Methods: executeUpdate, setBoolean, setInt, setString

0
		int recordsUpdated;
		PreparedStatement updateStmt;
 
		try { 
			updateStmt = connection.prepareStatement(QUERY_UPDATE);
			updateStmt.setString(++index, entity.getQualifiedClassName());
			updateStmt.setString(++index, entity.getMethodName());
			updateStmt.setString(++index, new String(entity.getArgumentsTypes()));
			updateStmt.setInt(++index, entity.getParameterOfInterest());
			updateStmt.setString(++index, entity.getDescription());
			updateStmt.setBoolean(++index, entity.isActive());
			updateStmt.setInt(++index, entity.getId());
			recordsUpdated = updateStmt.executeUpdate();
			// this should affect at most one record 
			if (recordsUpdated == 0){
				throw new NoSuchEntityException(); 
			}else if(recordsUpdated == 1) {
				success = true;
			} else { 
				// the update affected multiple records this should not happen! 
				throw new DAOException("Update of one BTPattern affected multiple records. This should not happen!");