Code example for PreparedStatement

Methods: executeUpdate, setInt, setNull, setString

0
		try { 
			updateStmt = connection.prepareStatement(DB_QUERY_UPDATE);
			//test parameters for null and set accordingly 
			if(entity.getApplication()!=null)
			{ 
				updateStmt.setInt(++index, entity.getApplication().getId());
			}else{ 
				updateStmt.setNull(++index, Types.INTEGER);
			} 
 
			 
			if(entity.getName(useDots)!=null)
			{ 
				updateStmt.setString(++index, entity.getFuzzyHash());
			}else{ 
				updateStmt.setNull(++index, Types.VARCHAR);
			} 
			 
			if(entity.getName(useDots)!=null)
			{ 
				updateStmt.setString(++index, entity.getName(useDots));
			}else{ 
				updateStmt.setNull(++index, Types.VARCHAR);
			} 
			 
			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;